Skip to content

misleading erros when failing anyof tests #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ssbarnea opened this issue Jan 12, 2020 · 7 comments
Closed

misleading erros when failing anyof tests #646

ssbarnea opened this issue Jan 12, 2020 · 7 comments
Labels
Enhancement Some new desired functionality

Comments

@ssbarnea
Copy link
Contributor

ssbarnea commented Jan 12, 2020

I discovered that anyOf related errors can be very mistleading.

- jobs:  # must fail as correct is 'job'

Validating snippet above with https://github.com/pycontribs/zuul-lint/blob/master/zuul_lint/zuul-schema.json would fail with a misleading error:

'nodeset' is a required property

Failed validating 'required' in schema[0]:
    {'required': ['nodeset']}

On instance:
    {'jobs': {'name': 'foo'}}

That schema allows multiple value and nodeset happens to just one of several. As you can see what user gets is an erros that makes no sense for him.

@Julian
Copy link
Member

Julian commented Jan 12, 2020

I assume you mean when you're using jsonschema.validate -- which is trying to be as beginner friendly as can be -- as you say, it can be misleading at times, but more often than not descending into errors ends up producing clearer errors for most cases, which is why that API does so.

If you don't though want that behavior, you can use jsonschema.DraftXValidator.iter_errors or .validate directly, and not call best_match on the result.

@ssbarnea
Copy link
Contributor Author

ssbarnea commented Jan 12, 2020

You are right I use validate at https://github.com/pycontribs/zuul-lint/blob/master/zuul_lint/__main__.py#L22 but I am going to test more advanced API.

Thanks a lot fo the quick reply. That new linter I am writing is very new stuff, is not even 10 hours since I started it. I am also new to jsonschema in general and I do not rule out that my schema may not be well defined.

I raised the bug at pycontribs/zuul-lint#2

@Julian
Copy link
Member

Julian commented Jan 12, 2020 via email

@Julian Julian added the Enhancement Some new desired functionality label Mar 28, 2020
@willson-chen
Copy link
Contributor

Same as #698, since validator of oneOf and anyOf, the error instance with longest ValidationError.path will be considered as the best match in best_match. And if the length of all ValidationError.path are the same, the first error instance will be returned default.

@Julian Julian closed this as completed in bd5ea73 Jul 26, 2022
@Julian
Copy link
Member

Julian commented Jul 26, 2022

I believe the commit I just pushed should make these kinds of cases clearer (by not recursing into them). Feel free to try it out and provide feedback, otherwise a release with it should come out in a day or two.

@ssbarnea
Copy link
Contributor Author

@Julian I tested 4.8.0 and I can see the benefits in improved messaging. It broke two tests on my suite but that only helped me upgrade it and fix the tests. Thanks for working on this.

@Julian
Copy link
Member

Julian commented Jul 28, 2022

Nice (other than the breakage :)! Thanks for the feedback and the report.

Julian added a commit that referenced this issue Mar 14, 2023
19947eaa1 test: unevaluatedProperties not affected by propertyNames
829270631 Check that large integers are multiples of small multipleOf
b59543f6e Merge pull request #647 from santhosh-tekuri/ref-start-slash
6e5d45d71 Merge pull request #646 from santhosh-tekuri/vocab-optional
0311dfda0 Merge pull request #651 from santhosh-tekuri/dynamicref-without-anchor
4503eeaf4 test: A $dynamicRef without anchor in fragment behaves identical to $ref
39af4c1ba test: $ref with absolute-path-reference
880c9933b test/vocabulary: ignore unrecognized optional vocabulary
fd80307ff Merge pull request #642 from santhosh-tekuri/time-2digit
a76ae650d Merge pull request #645 from json-schema-org/gregsdennis/add-vocab-tests-link
0e2b4eefd Merge pull request #643 from 0xSudarshan/main
2b78ccfc4 slight tweaking to wording
8716c4054 add link for vocab test suite to readme
c49ba5445 Fix an incorrect $schema identifier.
f0e5ce71e Added  test for schema-items alongside "ignored" additionalItems
76dae88ab Merge pull request #640 from santhosh-tekuri/refRemote-anchor
cb82e237c Merge pull request #641 from json-schema-org/gregsdennis/unevaluated-not-draft-next
e4afd233a test/format: hour, min, sec must be two digits
7efd51313 fix unevaluatedProperties/not tests for draft-next
e39c6ea6a test/refRemote: anchor within remote ref
bf51b32fb Merge pull request #639 from json-schema-org/additionalItems-unevaluatedItems
52160b368 Add a test for 2019's interaction between additional/unevaluatedItems
69a09a339 Fixed tests for annotation collection inside not.
e4e1a220b Draft7 if/then/else ref tests need to be wrapped in an allOf.
f5bd2f6c3 Merge pull request #632 from json-schema-org/ether/annotations-inside-not
626b433e5 test that annations are collected inside a "not"

git-subtree-dir: json
git-subtree-split: 19947eaa1289168a49edd21bb7a8aa2098069ae0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Some new desired functionality
Projects
None yet
Development

No branches or pull requests

3 participants