Skip to content

feat(validation): hand a named vendor's nonportable_extensions to its own validator - #697

Merged
jbonofre merged 4 commits into
apache:mainfrom
kayemkim:validation/vendor-validator-hook
Nov 12, 2026
Merged

jbonofre merged 4 commits into
apache:mainfrom
kayemkim:validation/vendor-validator-hook

Conversation

@kayemkim

@kayemkim kayemkim commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

validate.py treats nonportable_extensions payloads 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.
  • For every nonportable_extensions entry carrying that vendor_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 the data object and the location to the vendor's validator. Entries of other vendors are not handed over.
  • The validator is whatever callable the vendor's package registers under the entry point group ossie.vendor_validators, named by the vendor token from extensions/vendors.md: check(payload, site) -> Iterable[str], where site carries kind (model, dataset, field, metric, relationship, mapping), name and the owning dataset. 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.
  • Naming a vendor whose validator is not installed is an error before any file runs; a validator that raises is reported against its vendor instead of ending the file's report.
  • Core does not read _v or any other key of the payload; which shapes a validator accepts is its own contract.

validate.py is a uv script, so the package is visible only when it is on the run's path:

uv run --with <package> validation/validate.py --vendor THOUGHTSPOT model.yaml

Not in this PR

  • The first registered validator: wiring ThoughtSpot's existing stash reader (_v, forbidden identity keys) to this entry point is a small follow-up in apache/ossie-converters once this lands.
  • Moving the hook into a validation module under python/ that the SDK models share, with validate.py as 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.
  • A structured finding format (stable code, severity, path, spec link). The hook emits the script's current string form, every vendor message is an error, and a nonfatal channel arrives with that format rather than here.
  • Handing expressions in a vendor's dialect to the same validator. The entry point object leaves room for it.

Tests

validation/tests/test_vendor_validators.py fixes 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 --vendor flags run each vendor once, and --vendor without a name prints usage. One existing CLI test fakes validate_document and now accepts the new parameter.

@jbonofre
jbonofre self-requested a review November 4, 2026 14:02
Comment thread validation/validate.py Outdated
errors.extend(validate_field_shadowing(data))
errors.extend(validate_metric_scoping(data))
errors.extend(validate_sql(data))
if vendors:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Suggested change
if vendors:
if vendors and clean():

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 02fa5f3, with a test that a duplicate dataset name withholds the document from the validator, and one that a warning does not.

Comment thread validation/validate.py Outdated
try:
result = validator(payload, site)
messages = [result] if isinstance(result, str) else list(result or [])
except Exception as e:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Suggested change
except Exception as e:
except (Exception, SystemExit) as e:

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 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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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: [])

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 02fa5f3 as an autouse fixture; the file passes without sqlglot installed now.

@kayemkim

kayemkim commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

Pushed 02fa5f3 with the three changes: the vendor checks run only when clean() still holds after the semantic checks, the handler catches SystemExit together with Exception, and the vendor test file patches validate_sql out through an autouse fixture. While there, entry_point.load() had the same hole, since a CLI module can exit while it is imported, so the loader catches it too and reports it before any file runs. Four tests pin these, and the vendor tests pass without sqlglot installed.

@kayemkim

kayemkim commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Rebased onto main for #634, which added validate_metric_agreement at the same point of validate_document. It now runs before the vendor hook, and since it only warns, a drift warning does not withhold the document from a validator. Nothing else changed; the suite is 588 passed on bd9e1ab.

#522 renames custom_extensions to nonportable_extensions in this file too. If it lands first, I will rename here to match.

@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.

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",

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.

#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?

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.

Bumped in 21ab77e. The other half of those 13 failures was the #522 rename, which is in the same commit.

Comment thread validation/validate.py Outdated
# 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"))

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.

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?

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.

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.

Comment thread validation/validate.py Outdated
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():

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.

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?

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.

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
@kayemkim
kayemkim force-pushed the validation/vendor-validator-hook branch from bd9e1ab to 21ab77e Compare November 11, 2026 10:24
@kayemkim kayemkim changed the title feat(validation): hand a named vendor's custom_extensions to its own validator feat(validation): hand a named vendor's nonportable_extensions to its own validator Nov 11, 2026
@kayemkim

Copy link
Copy Markdown
Member Author

Rebased onto main and pushed 21ab77e. #522 changed more than the name here: data is an object now, so the hook no longer decodes anything and hands the validator a copy of the object. The tests moved to 0.3.0.dev0 and object payloads, and the suite passes on current main. I updated the title and the description to match.

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

@jbonofre
jbonofre merged commit b47f6ea into apache:main Nov 12, 2026
16 checks passed
djwaldo added a commit to djwaldo/ossie-converters that referenced this pull request Nov 15, 2026
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>
christianeu-db pushed a commit to apache/ossie-converters that referenced this pull request Nov 16, 2026
…#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>
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.

3 participants