Skip to content

feat(validation): give a vendor validator the object its entry sits on, and warnings - #759

Merged
christianeu-db merged 3 commits into
apache:mainfrom
kayemkim:vendor-hook-node-severity
Nov 20, 2026
Merged

christianeu-db merged 3 commits into
apache:mainfrom
kayemkim:vendor-hook-node-severity

Conversation

@kayemkim

@kayemkim kayemkim commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

The vendor hook from #697 hands a validator its data object and the name of the site. The first validator registered on it, ThoughtSpot's in apache/ossie-converters, says in its docstring what it could not write yet: a check that the values it stashed still match the document. That check needs the object the entry sits on, and it needs a finding that does not fail the file, because a stale stash sits in a document that is valid Ossie. This is the follow-up I said I would open on the dev@ thread Vendor-specific validation: what the converters check today, and where a shared hook would go.

  • site.node is a copy of the object the entry sits on: the field, metric, dataset or relationship, or the whole document for a model or mapping site. The copy has no nonportable_extensions where the schema places them, so the rule from feat(validation): hand a named vendor's nonportable_extensions to its own validator #697 that other vendors' entries are not handed over still holds. Each call gets its own copy.
  • A finding may be a dict with a message and a severity of error or warning. A warning is printed as [Vendor NAME] Warning: Field 'orders.amount' in model 'sales': <message> and does not fail the file, the same way the built-in warnings work. A message string is still an error, so an existing validator behaves as before. I ran ThoughtSpot's vendor_check.check through this branch and through main and the output is the same.
  • A dict with another key, another severity or no message string is reported as an error against the vendor, and so is a message that is empty.
  • Returned on its own, "" or {} is no finding, like None and []. An item of a returned list is always a finding, so [{}] is an error.

Two things change for a validator written against #697:

  • ExtensionSite is a frozen dataclass and no longer a named tuple, so that node stays out of equality and hashing. Reading site.kind, site.name and site.dataset works as before. Unpacking or indexing site does not. extensions/vendors.md describes attribute access, and the ThoughtSpot validator does not read site.
  • A finding that raises while it is read is reported against its vendor. On main it ended the file's report as a bug in the script.
  • iter_nonportable_extensions yields (site, owner, entry) where it yielded (site, entry). Only validate_vendor_extensions calls it in this repository.

Open choice

A dict with a key other than message and severity is rejected, so that code and path from the finding format Andrew proposed are added on purpose later. The cost is that a validator written for a later contract fails on an older validate.py. Ignoring unknown keys is the other option, and I am fine with either.

Not in this PR

  • Codes, document paths and spec links on a finding. This adds the severity only.
  • A self-test for the entry point registration, which Damian suggested on the thread.

Tests

validation/tests/test_vendor_validators.py adds: the object each of the six sites and a mapping document receives, that it carries no entries at the places the schema defines and keeps a key of that name under ai_context, that each entry gets its own copy and the document is unchanged, that an object holding itself through a YAML alias is copied, that two sites are equal whatever their copies hold, a warning through validate_document and through the CLI with and without an error next to it, a dict with and without a severity, the empty return values, the malformed shapes including an empty message, and a finding that raises when read. The existing tests are unchanged.

…n, and warnings

A vendor validator received the data object and the name of the site, so it
could not compare its payload with the field, dataset or relationship the
entry is attached to, and every message it returned failed the file.

- site.node is a copy of the object the entry sits on, without the
  nonportable_extensions on it or on the objects nested in it, so no other
  vendor's payload is handed over. ExtensionSite becomes a frozen dataclass
  so that the copy stays out of equality and hashing.
- A finding may be a dict with a message and a severity. A warning is
  printed and does not fail the file. A message string stays an error, so
  existing validators behave as before.
- Findings are read where the validator runs, so one that raises while it
  is read is reported against its vendor.

Generated-by: Claude Code
Comment thread validation/validate.py Outdated
Comment on lines +2708 to +2709
if not isinstance(finding, Mapping):
return "error", str(finding)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that a dict finding is checked strictly: there is one format, and a validator that breaks the format is told so. A finding that is not a dict doesn't get the same treatment, though. It is turned into a string and reported as if it were the message:

Validator returns Reported as
[None] [Vendor ACME] Model 'sales': None
[7] [Vendor ACME] Model 'sales': 7
[("stale", "warning")] [Vendor ACME] Model 'sales': ('stale', 'warning'), an error, so the warning that was meant is lost

A validator that guesses the format, a tuple for instance, gets a confusing error instead of being told the finding has the wrong shape. Could anything that is neither a string nor a dict be reported the same way as a malformed dict?

Suggested change
if not isinstance(finding, Mapping):
return "error", str(finding)
if isinstance(finding, str):
return "error", finding
if not isinstance(finding, Mapping):
return "error", f"validator returned a finding that is neither a string nor a dict: {finding!r}"

extensions/vendors.md would need the matching change ("a returned item that is neither a string nor a dict is reported as an error with its text"), plus a test case or two next to the malformed-dict ones.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in eff387a, with your suggestion plus two things I found while testing it. A single value returned without a list, return 7, was still reported as a TypeError raised by the validator, so it now gets the same report. And the string branch returns str(finding), since a str subclass that raises while it is formatted would otherwise escape as a bug in the script. Tests cover None, 7, the tuple, an exception and bytes, and extensions/vendors.md is changed to match. One case stays as it was: a tuple returned bare, return ("stale", "warning"), is read as two messages, since it cannot be told apart from a sequence of strings. The docs say so now.

Comment thread validation/validate.py
Comment on lines +2505 to +2507
# A copy of the object the entry sits on, see without_extensions(). Two sites
# are the same site whatever their copies hold.
node: dict[str, object] | None = dataclasses.field(default=None, compare=False, repr=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a field or metric site, site.node is only that object, so a validator can't see the dataset that owns it or the rest of the document. Would it make sense to also hand over the owning dataset, e.g. site.parent?
A site.document alone would leave the validator to find the field again by name, which is ambiguous when two or more datasets have a field with the same name. Passing the owning dataset directly avoids that lookup. It can be added later without breaking anything, so fine as a follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that it is additive, and I would rather take it as a follow-up. What the parent is differs by site: the dataset for a field or a dataset-scoped metric, the model for the rest. A relationship may need its two endpoint datasets more than its parent. Damian's example is a join that came back owned by the wrong table, so I would like to see what that check has to read before fixing the shape.

… a dict as malformed

Such an item was printed with str() as if it were the message, so a tuple
like ("stale", "warning") in the returned list came back as an error
reading ('stale', 'warning'). It is now reported the way a dict of another
shape is, and shown with repr(), so None or an exception in the list is
named and not printed as text.

A single value that is not iterable gets the same report where it was a
TypeError raised in the script. A message that is a str subclass is
turned into a plain string where the validator runs.

Generated-by: Claude Code
@djwaldo

djwaldo commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

This does what the follow-up promised, and it covers the ThoughtSpot case.
site.node carries the three things our witnesses compare against: a dataset's
source, a relationship's endpoints, a field's expression. The severity channel
makes a stale witness a warning, which is what kept that check unshipped. Ran
the suite on 45b01bb: 44 passed.

One finding, and one note on the signature changes.

The empty-value rule depends on the container

A falsy finding means "nothing to report" only when the validator returns a
bare Mapping. Measured against validate_vendor_extensions, not read off the
diff:

returned result
{} no finding
[{}] error, "a finding without a message string"
"" error, with an empty message
[""] error, with an empty message

The cause is in validate_vendor_extensions: returned = [result] if result else [] applies to a Mapping only. A falsy string does not get it, and
nothing inside a list gets it.

Two consequences. The same value answers differently depending on whether it is
wrapped, so a validator building [finding(x) for x in items] with a
"nothing" sentinel of {} gets errors where a bare return {} is silent. And
"" produces a finding with no text: [Vendor ACME] Model 'sales': .

vendors.md describes the other half of this: "A dict with another key,
another severity, or no message string is reported as an error that names
the problem." An empty dict has no message string, so the document says it is
an error and the code says it is nothing.

Either reading is defensible. Falsy means nothing is the kinder contract, and
test_an_empty_dict_is_no_finding pins it deliberately. Which did you intend?
If it is the kind one, "" and [{}] should follow it, and vendors.md needs
a sentence for the empty case. If it is the strict one, the Mapping shortcut
goes and {} becomes an error like the rest.

I have not suggested a patch, because the answer is a contract decision rather
than a defect.

The signature changes are breaking

ExtensionSite moves from NamedTuple to a frozen dataclass, so it no longer
unpacks or indexes as a tuple. iter_nonportable_extensions yields
(site, owner, entry) where it yielded (site, entry).

Nothing in this repository depends on either, so this is a note rather than an
objection. Both are importable and iter_nonportable_extensions reads as a
helper, so a line in the PR body would help anyone who has reached for it.

Checked and clean

  • The copy is deep, and an object holding itself through ai_context survives.
  • nonportable_extensions is stripped only where the schema places it, so a
    key of that name under ai_context is kept.
  • Site equality and hashing ignore node, so two sites are one site.
  • A validator that mutates site.node cannot reach the document.

…eport an empty message

A validator that returned {} had no finding while "" printed an error
with no text, and extensions/vendors.md described neither. An empty
string returned on its own is now no finding, as an empty dict already
was.

An item of a returned list is still a finding, so {} in a list stays an
error. A message that is empty or only whitespace, as a string or under
"message", is reported as malformed where it was printed with nothing
after the site, as an error or, with the severity "warning", a warning.

One more test pins that a message of a str subclass is printed as plain
text.

Generated-by: Claude Code
@kayemkim

Copy link
Copy Markdown
Member Author

The rule I meant is about the return value, not about a finding. An empty return is no findings, the way None and [] are, and {} was silent as an empty return. The code did not hold to that for "", and vendors.md did not say it.

fc95451 makes it hold. return "" is no finding now, like return {}, and the docs say so. Inside a list every item is a finding, so [{}] stays an error. Skipping empty items there would also skip [None], which Andrew asked to have reported, so a validator that builds [finding(x) for x in items] has to leave its "nothing" items out.

The finding with no text is gone. A message that is empty or only whitespace, whether [""], {"message": ""} or return " ", is reported as validator returned a finding with an empty message: ''. That makes {"message": "", "severity": "warning"} an error where it was a warning.

On the signatures, the PR body already had the ExtensionSite change. I added iter_nonportable_extensions, which I had left out.

No need to build a synthetic example of the join case.

@christianeu-db christianeu-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @kayemkim!

@christianeu-db
christianeu-db merged commit 94cf86b into apache:main Nov 20, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants