Repository navigation
feat(validation): hand a named vendor's nonportable_extensions to its own validator - #697
Conversation
| errors.extend(validate_field_shadowing(data)) | ||
| errors.extend(validate_metric_scoping(data)) | ||
| errors.extend(validate_sql(data)) | ||
| if vendors: |
There was a problem hiding this comment.
Vendor checks run here even when the checks just above reported errors: clean() was true on entering this block, but nothing checks it again after validate_unique_names ... validate_sql. vendors.md says vendor check run on "a document that passed the schema and the other checks", so a validator can be handed a model with duplicate dataset names or dangling references it was told it would never see.
| if vendors: | |
| if vendors and clean(): |
There was a problem hiding this comment.
Done in 02fa5f3, with a test that a duplicate dataset name withholds the document from the validator, and one that a warning does not.
| try: | ||
| result = validator(payload, site) | ||
| messages = [result] if isinstance(result, str) else list(result or []) | ||
| except Exception as e: |
There was a problem hiding this comment.
SystemExit is not an Exception, so a validator that calls sys.exit() (easy to do when it reuses a converter's CLI code) gets past this handler and validate_file catch all, and ends the run.
With sys.exit() or sys.exit(0) the process exits 0, so an earlier failed file reads as a pass in CI. With a non zero code, the remaining files are never checked.
| except Exception as e: | |
| except (Exception, SystemExit) as e: |
There was a problem hiding this comment.
Done in 02fa5f3; sys.exit(0) from a validator now reads validator raised SystemExit: 0 and fails the file, and the loader catches an exit on import the same way.
| import pytest | ||
|
|
||
| yaml = pytest.importorskip("yaml") | ||
| pytest.importorskip("jsonschema") |
There was a problem hiding this comment.
This module only skips when yaml or jsonschema is missing, but without sqlglot validate_sql adds [SQL] Warning: sqlglot not installed ... to the results. The tests that assert errors == [] or an exact count on validate_document (test_payloads_stay_opaque_without_a_vendor, test_bad_json_is_reported_once_and_not_handed_over, test_unnamed_vendors_are_not_decoded, ...) then fail instead of skipping. CI passes only because sqlglot is installed there.
test_validate.py handles this with skipif(not _VALIDATE.SQLGLOT_AVAILABLE). Since nothing here exercises SQL, an autouse fixture would keep these tests running everywhere instead:
@pytest.fixture(autouse=True)
def _no_sql_check(monkeypatch: pytest.MonkeyPatch) -> None:
# These tests are about vendor payloads; keep the sqlglot warning out of the results.
monkeypatch.setattr(_VALIDATE, "validate_sql", lambda data: [])There was a problem hiding this comment.
Done in 02fa5f3 as an autouse fixture; the file passes without sqlglot installed now.
|
Pushed 02fa5f3 with the three changes: the vendor checks run only when |
02fa5f3 to
bd9e1ab
Compare
|
Rebased onto main for #634, which added #522 renames |
christianeu-db
left a comment
There was a problem hiding this comment.
One fix before merge: the new tests pin the old version and fail on current main (inline); the other two are non-blocking questions. @jbonofre, your three points look addressed at the latest head; could you take another look?
| def _model() -> dict: | ||
| """A valid model with an ACME extension at each place the schema allows one.""" | ||
| return { | ||
| "version": "0.2.0.dev0", |
There was a problem hiding this comment.
#691 moved the version on main to 0.3.0.dev0, so on a merge with current main 13 of these tests fail with [Schema] version: '0.3.0.dev0' was expected. The checks here are green only because they ran on the older base. Could we bump it here?
| # data that is not a string fails the schema first; a direct call on an unvetted | ||
| # document still gets a report instead of a TypeError. | ||
| try: | ||
| payload = json.loads(entry.get("data")) |
There was a problem hiding this comment.
json.loads keeps the last of a repeated key and accepts NaN, so this payload reaches the validator as {'_v': 2, 'x': nan} with no report:
{"_v": 1, "_v": 2, "x": NaN}The SDK's from_ossie_json rejects a repeated key with unique_json_object from _loading.py, which this script already loads, and NaN is not JSON under RFC 8259. Not a blocker: could the decode use object_pairs_hook=unique_json_object and a parse_constant that raises?
There was a problem hiding this comment.
With data as an object there is no json.loads left on this path. A repeated _v under data is a YAML duplicate key, which the loader rejects for the whole file, and .nan is a schema error from validate_extension_data, so the validator sees neither. A test pins the second.
| errors.extend(validate_metric_agreement(data)) | ||
| # A validator is promised a document the checks above accepted; a warning | ||
| # from them does not withhold it. | ||
| if vendors and clean(): |
There was a problem hiding this comment.
vendors.md scopes this to semantic models, but a mapping document can carry custom_extensions too, and --vendor ACME on a mapping whose ACME entry has data: "{not json" prints Validation PASSED with no sign that the check was skipped. Not a blocker: should the hook also read the mapping's entries, or say that it skipped them?
There was a problem hiding this comment.
I went with reading them. A mapping document carries the entries at its top level only, so --vendor ACME now hands those to the validator at a site of kind mapping, after the mapping cross-checks. It stops at the file being validated; the entries of the model a mapping references are not handed over.
…validator custom_extensions payloads stay opaque to validate.py. A converter that wants its own payload checked has had no place to plug in, so each one re-implements the read in its own CLI with its own strictness. Add --vendor NAME. For every custom_extensions entry carrying that vendor_name, at any of the six places the schema allows one, the script decodes data as JSON, reports a payload that is not JSON, and hands the decoded value with its location to the callable the vendor's package registers under the entry point group ossie.vendor_validators, named by the vendor token. Messages come back as [Vendor NAME] <location>: .... Nothing runs without the flag, entries of other vendors are not read, naming a vendor whose validator is not installed is an error before any file runs, and a validator that raises is reported against its vendor instead of ending the file's report. Generated-by: Claude Code
The registry names the tokens; say what --vendor <token> does with them and that the package has to be on the uv run path. Generated-by: Claude Code
…s.exit() Two gaps between extensions/vendors.md and the hook, the same hole in the loader, and one gap in the tests. validate_document ran the vendor checks whenever a vendor was named: clean() was true on entering the block, but nothing checked it again after the semantic checks, so a validator could be handed a model with duplicate dataset names or dangling references it was told it would never see. The vendor checks now wait for those checks the way the ontology and mapping checks do; a warning from them does not withhold the document. SystemExit is not an Exception, so a validator that calls sys.exit(), easy to do when it reuses a converter's CLI code, passed both the hook's handler and the catch-all in validate_file and ended the run at that file: with sys.exit() or sys.exit(0) the process exited 0 and an earlier failed file read as a pass, with any other code it exited with that code. Either way the remaining files were never checked. The same CLI module can exit while it is imported, and entry_point.load() had the same hole. Both handlers now catch SystemExit with the exceptions and report it against the vendor; a bare sys.exit() reads "validator raised SystemExit" with no empty detail after it. test_vendor_validators.py only skipped without yaml or jsonschema, but without sqlglot validate_sql adds its warning to every result and the exact assertions failed; CI passed because sqlglot is installed there. Nothing in the file exercises SQL, so an autouse fixture patches validate_sql out and the tests run everywhere. Four tests pin the above: an error from the other checks withholds the document and a warning does not, a validator that exits is reported like one that raises, and an entry point that exits on import is an error before any file runs. vendors.md says "raises, or exits" for the validator.
The extension field is now nonportable_extensions and its data is an object, where the hook read custom_extensions and decoded a JSON string. On a merge with main the hook found no entries, and the vendor tests failed at the schema with the old version and the old field name. The hook reads nonportable_extensions and hands a validator a copy of the data object. The decode step and its "data is not valid JSON" report are gone: the schema requires an object, the JSON-value check on data rejects what JSON cannot represent, and a validator still only sees a document those checks accepted. A repeated key under data never gets that far, since the loader rejects it for the whole document. Decoding used to give every call a fresh value; the copy keeps that, so a validator that changes its payload cannot change what the next site sees when two entries share one object through a YAML alias. A mapping document carries nonportable_extensions at its top level, and --vendor on one used to pass without a word. Its entries now go to the validator too, at a site of kind "mapping", after the mapping cross-checks. Only the entries of the file being validated are handed over, not those of the documents a mapping references, and an ontology document has none. The tests move to 0.3.0.dev0 and object payloads. The decode tests give way to these: a value JSON cannot represent is reported by the schema check and withholds the document, data that is not an object is reported on a direct call, a payload shared through an alias is copied for each site, a mapping document's entries reach the validator, an error from the mapping cross-checks withholds them, and an ontology document yields no entries. Generated-by: Claude Code
bd9e1ab to
21ab77e
Compare
|
Rebased onto main and pushed 21ab77e. #522 changed more than the name here: |
jbonofre
left a comment
There was a problem hiding this comment.
Thanks @kayemkim!
All three points from my earlier review (clean() gating after semantic checks, catching SystemExit in both the hook and entry point loader, and the validate_sql autouse fixture) are cleanly addressed, and the updates for nonportable_extensions object payloads and mapping documents are great.
Great work!
apache/ossie#697 adds a `--vendor NAME` hook: core hands the `data` object of each entry carrying that vendor_name to the callable the vendor's own package registers under the entry point group `ossie.vendor_validators`. Kyoung Min Kim offered ThoughtSpot as the first checker; this is it. `vendor_check.check(payload, site)` reports three things and raises nothing: a payload that is not an object, a `_v` this converter does not recognise, and an instance-local identity key at any depth. That is the scope agreed on the dev@ thread for a first checker. The first of those three is unreachable through the hook as merged -- core reports a non-object `data` itself and skips the call -- and is kept as a guard on a direct call, which the comment on it now says. It is a separate module rather than a reuse of `stash.read_stash` deliberately. Both answer the same questions about the same payload and must end differently: the reader aborts a conversion it cannot trust, a validator names everything wrong in one pass. The shared part is one comparison and one scan; the control flow is the part that has to differ, and a test pins the asymmetry so neither drifts alone. No witness check yet. It needs the owning Ossie object (every witness is a comparison against it) and a severity that does not fail the file, and the hook has neither today. Both are promised as a follow-up to #697. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…#205) apache/ossie#697 adds a `--vendor NAME` hook: core hands the `data` object of each entry carrying that vendor_name to the callable the vendor's own package registers under the entry point group `ossie.vendor_validators`. Kyoung Min Kim offered ThoughtSpot as the first checker; this is it. `vendor_check.check(payload, site)` reports three things and raises nothing: a payload that is not an object, a `_v` this converter does not recognise, and an instance-local identity key at any depth. That is the scope agreed on the dev@ thread for a first checker. The first of those three is unreachable through the hook as merged -- core reports a non-object `data` itself and skips the call -- and is kept as a guard on a direct call, which the comment on it now says. It is a separate module rather than a reuse of `stash.read_stash` deliberately. Both answer the same questions about the same payload and must end differently: the reader aborts a conversion it cannot trust, a validator names everything wrong in one pass. The shared part is one comparison and one scan; the control flow is the part that has to differ, and a test pins the asymmetry so neither drifts alone. No witness check yet. It needs the owning Ossie object (every witness is a comparison against it) and a severity that does not fail the file, and the hook has neither today. Both are promised as a follow-up to #697. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Summary
validate.pytreatsnonportable_extensionspayloads as opaque, so a converter that wants its own payload checked has had nowhere to plug in; each one re-implements the read in its own CLI with its own strictness (the survey in the dev@ thread Vendor-specific validation: what the converters check today, and where a shared hook would go counts five strict, three warning, four silent, two none across fourteen converters).This adds the hook that thread settled on:
--vendor NAME, repeatable. Nothing runs without it.nonportable_extensionsentry carrying thatvendor_name, at any of the six places the schema allows one in a semantic model or at the top level of a mapping document, the script hands a copy of thedataobject and the location to the vendor's validator. Entries of other vendors are not handed over.ossie.vendor_validators, named by the vendor token fromextensions/vendors.md:check(payload, site) -> Iterable[str], wheresitecarrieskind(model, dataset, field, metric, relationship, mapping),nameand the owningdataset. Each message comes back as[Vendor NAME] Field 'orders.amount' in model 'sales': <message>, in the same list as the other checks, so it fails the file the same way._vor any other key of the payload; which shapes a validator accepts is its own contract.validate.pyis a uv script, so the package is visible only when it is on the run's path:Not in this PR
_v, forbidden identity keys) to this entry point is a small follow-up in apache/ossie-converters once this lands.python/that the SDK models share, withvalidate.pyas a thin CLI, as Andrew proposed. There is no such module yet, so this keeps the hook in the script; the entry point contract does not change when it moves.Tests
validation/tests/test_vendor_validators.pyfixes the contract: payloads stay opaque without the flag, each of the six sites reaches the validator with its payload and the expected prefix, other vendors are not handed over, a value JSON cannot represent withholds the document, a payload shared through an alias is copied for each site, a mapping document's entries arrive after its cross-checks, a single string is one message and None is none, a raising validator is reported with the traceback on stderr, a missing, doubly registered, non-importable or non-callable entry point is an error before any file runs, several--vendorflags run each vendor once, and--vendorwithout a name prints usage. One existing CLI test fakesvalidate_documentand now accepts the new parameter.