Repository navigation
feat(validation): give a vendor validator the object its entry sits on, and warnings - #759
Conversation
…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
| if not isinstance(finding, Mapping): | ||
| return "error", str(finding) |
There was a problem hiding this comment.
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?
| 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.
There was a problem hiding this comment.
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.
| # 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
This does what the follow-up promised, and it covers the ThoughtSpot case. One finding, and one note on the signature changes. The empty-value rule depends on the containerA falsy finding means "nothing to report" only when the validator returns a
The cause is in Two consequences. The same value answers differently depending on whether it is
Either reading is defensible. Falsy means nothing is the kinder contract, and I have not suggested a patch, because the answer is a contract decision rather The signature changes are breaking
Nothing in this repository depends on either, so this is a note rather than an Checked and clean
|
…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
|
The rule I meant is about the return value, not about a finding. An empty return is no findings, the way fc95451 makes it hold. The finding with no text is gone. A message that is empty or only whitespace, whether On the signatures, the PR body already had the No need to build a synthetic example of the join case. |
christianeu-db
left a comment
There was a problem hiding this comment.
LGTM, thanks @kayemkim!
Summary
The vendor hook from #697 hands a validator its
dataobject 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.nodeis a copy of the object the entry sits on: the field, metric, dataset or relationship, or the whole document for amodelormappingsite. The copy has nononportable_extensionswhere 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.messageand aseverityoferrororwarning. 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'svendor_check.checkthrough this branch and through main and the output is the same.""or{}is no finding, likeNoneand[]. An item of a returned list is always a finding, so[{}]is an error.Two things change for a validator written against #697:
ExtensionSiteis a frozen dataclass and no longer a named tuple, so thatnodestays out of equality and hashing. Readingsite.kind,site.nameandsite.datasetworks as before. Unpacking or indexingsitedoes not.extensions/vendors.mddescribes attribute access, and the ThoughtSpot validator does not readsite.iter_nonportable_extensionsyields(site, owner, entry)where it yielded(site, entry). Onlyvalidate_vendor_extensionscalls it in this repository.Open choice
A dict with a key other than
messageandseverityis rejected, so thatcodeandpathfrom the finding format Andrew proposed are added on purpose later. The cost is that a validator written for a later contract fails on an oldervalidate.py. Ignoring unknown keys is the other option, and I am fine with either.Not in this PR
Tests
validation/tests/test_vendor_validators.pyadds: 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 underai_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 throughvalidate_documentand 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.