Skip to content

test(validation): pin schema-first reporting for malformed documents and announce skipped semantic checks - #271

Merged
kayemkim merged 1 commit into
apache:mainfrom
mattfaltyn:fix/validator-non-mapping-yaml
Nov 2, 2026
Merged

kayemkim merged 1 commit into
apache:mainfrom
mattfaltyn:fix/validator-non-mapping-yaml

Conversation

@mattfaltyn

@mattfaltyn mattfaltyn commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#383 already prevents malformed documents from reaching semantic checks on main. This PR builds on that behavior by pinning schema-first reporting and explaining when semantic checks are skipped.

  • Add regression tests for empty, sequence, scalar, and malformed documents to the pytest suite run by Validation CI.
  • Cover a flat document containing both schema and semantic errors to verify that schema errors defer the semantic diagnostics.
  • Print a notice when schema errors cause semantic checks to be skipped, and document the validation order in docs/index.md.
  • Annotate the validate_schema input as object to reflect the values it validates.

Behavior

Schema-invalid documents continue to exit 1 with their schema errors. The new notice explains that semantic checks were skipped until those errors are fixed. A subsequent run can then report any remaining semantic errors.

The specification, CLI arguments, and dependency set are unchanged.

Related context

Related to #270. The crash prevention and schema-first gate are already present on main through #383; this PR adds reporting, regression coverage, documentation, and the input annotation.

Validation

All Validation CI commands pass locally on Python 3.13.13:

uv run validation/test_validate.py
uv run --with pytest --with pyyaml --with jsonschema --with sqlglot -m pytest validation/tests/
uv run --with pytest --with jsonschema --with ./python -m pytest python/tests/
uv run scripts/generate-spec-types.py --check
uv run validation/validate.py examples/tpcds_semantic_model.yaml
uv run validation/validate.py examples/flights.yaml --schema ontology/ontology.json
uv run validation/validate.py examples/flights.ontology.yaml --schema ontology/ontology.json
uv run validation/validate.py examples/flights.semantic_model.yaml
uv run validation/validate.py examples/flights.mapping.yaml --schema ontology/mapping.json
uv run validation/validate.py examples/renamed_fields.yaml
python3 -m py_compile validation/validate.py validation/tests/test_validate.py
git diff --check origin/main...HEAD

Results: 59 unittest tests, 495 validation pytest tests, and 268 shared Python model tests passed. Schema synchronization, all example validations, compilation, and diff checks passed. The mapping example emitted two non-fatal SQL-expression warnings.

Checklist

  • Regression cases are in the pytest suite run by Validation CI.
  • Schema-first reporting and the skipped-checks notice are documented and tested.
  • All relevant local checks pass.
  • No new source files or third-party dependencies are added.

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

Picked this up since #270 still reproduces on main (831f48e): /dev/null, [], a bare scalar, and semantic_model: invalid all end in an AttributeError traceback. With the validate.py hunk from this PR applied on top of main, all four exit 1 with the [Schema] line and no traceback, the existing suites pass (uv run validation/test_validate.py and pytest on validation/tests/), and the 14 Ossie documents under examples/ and converters/**/tests produce byte-identical output before and after.

Two things before this can go in:

  1. It no longer merges. Main gained its own validation/test_validate.py in #337 (a uv script that CI runs directly), so this PR's file is an add/add conflict, and it also points at core-spec/osi-schema.json, which is now ossie-schema.json. The four cases would fit naturally as pytest functions in validation/tests/test_validate.py, which CI already runs.

  2. if not errors and ... changes what a schema-invalid document reports. On main a document with one unknown property plus a duplicate dataset name and a dangling relationship target gets all three errors; with this change it gets only the schema one, and the other two show up on the next run. That is a defensible trade for never crashing, but it is a behaviour change worth stating in the PR, and maybe worth one line in the output ("semantic checks skipped until schema errors are fixed") so nobody is surprised. Gating on shape instead (root is a mapping, semantic_model is a list of mappings) would keep today's behaviour for the common case, but the semantic checks would still need guards for deeper malformed values, so I can see why the simpler gate was chosen.

For ordering, #373 and #383 both edit the same part of main() (#383 changes the semantic_model gate itself), so whichever lands first, the others will need a small rebase.

flyrain
flyrain previously approved these changes Sep 14, 2026

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

+1 Thanks @mattfaltyn. cc @khush-bhatia

@mattfaltyn
mattfaltyn force-pushed the fix/validator-non-mapping-yaml branch 2 times, most recently from b5b743b to 972e377 Compare September 15, 2026 15:54
@mattfaltyn

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. Both points are addressed.

Main gained its own validation/test_validate.py in #337

Rebased onto current main, preserved that suite, and moved the four regression cases into validation/tests/test_validate.py, which Validation CI runs. The tests now use the renamed ossie-schema.json through the validator default.

it is a behaviour change worth stating in the PR

Agreed. The CLI now states when semantic checks are skipped, the behavior is documented in the PR description and docs/index.md, and a regression test covers documents containing both schema and semantic errors.

Thanks again for the clear guidance.

@mattfaltyn
mattfaltyn requested a review from kayemkim September 15, 2026 15:57

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

Re-ran the rebased head (972e377) merged into current main (fc6c9df): the validation-ci matrix (3.11 to 3.14) passes, the four #270 inputs (empty file, [], a bare scalar, semantic_model: invalid) exit 1 with a [Schema] line and the new notice instead of a traceback, and the 14 Ossie documents under examples/ and converters/** keep their exit codes, the only output change being the notice on the three ontology files that already fail the core schema. The tests in validation/tests/, the notice, and the docs/index.md line cover both points I raised. LGTM.

One ordering note: #383 (approved yesterday) adds the same not errors and isinstance(data, dict) gate on its own, and with that branch alone the four inputs also stop crashing. If it lands first, this conflicts in both files and reduces to the notice, the docs line, and the tests, which #383 does not have for malformed shapes. The test_schema_errors_defer_semantic_errors fixture would then need the flat shape (datasets: at the root); otherwise the wrapper itself trips the schema and the duplicate-name and dangling-target parts of the case are no longer exercised.

@mattfaltyn

mattfaltyn commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author

The test_schema_errors_defer_semantic_errors fixture would then need the flat shape (datasets: at the root); otherwise the wrapper itself trips the schema and the duplicate-name and dangling-target parts of the case are no longer exercised.

Done, thank you. I rebased onto current main, converted the fixture to the flat root shape, and kept both the duplicate dataset and dangling target so the test still proves schema errors defer semantic checks. The validation suites pass locally.

Signed-off-by: Matt Faltyn <faltyn.matthew@gmail.com>

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

Since the rebase this sits on #383, which already stops the four #270 inputs at the [Schema] line on main, so what the PR adds now is the skipped-checks notice, the tests for the malformed shapes, the docs line and the object annotation. The title and summary still describe the fix #383 landed, and the title becomes the squash commit. Something like test(validation): pin schema-first reporting for malformed documents and announce skipped semantic checks would match what is left; with that I am glad to approve and merge.

@mattfaltyn mattfaltyn changed the title fix(validation): report schema errors for invalid YAML test(validation): pin schema-first reporting for malformed documents and announce skipped semantic checks Nov 1, 2026
@mattfaltyn

Copy link
Copy Markdown
Contributor Author

Thanks @kayemkim! Updated the title and summary as suggested to reflect the remaining changes and credit #383 for the crash fix. All CI-equivalent validation checks pass locally.

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

The title and summary now describe the remaining changes and leave the crash fix with #383. 6234c33 merged onto today's main, where #669 touched the same loader path, stays green across the matrix. LGTM, merging.

@kayemkim
kayemkim merged commit 2508144 into apache:main Nov 2, 2026
8 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.

3 participants