Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat invalid pattern property as unevaluated #1073

Conversation

ikonst
Copy link
Contributor

@ikonst ikonst commented Mar 27, 2023

This addresses an "error message" issue, not a validation issue, so no need to update the test suite.

For regular properties, a property which failed validation would be also deemed "unevaluated", thus resulting in two messages, e.g.

validate(
    schema={"properties": {"foo": {"type": "string"}}},
    instance={"foo": 42},
)

would result in 2 errors:

  • 42 is not of type 'string'
  • unevaluated property 'foo'

With this change, pattern properties would have the same behavior:

validate(
    schema={"patternProperties": {"^foo": {"type": "string"}}},
    instance={"foo": 42},
)

馃摎 Documentation preview 馃摎: https://python-jsonschema--1073.org.readthedocs.build/en/1073/

@Julian
Copy link
Member

Julian commented Mar 27, 2023

Thanks for the PR. Though as I said I'm not sure I'll be comfortable merging it strictly for improving the error at the minute -- unevaluatedProperties already does lots of unnecessary work (re-walking schemas) which is in need of fixing to support JSON Schema's "new computation model" that includes stateful keywords in core. Doing a whole second validation pass is going to be even more inefficient, not to mention that unevaluatedProperties is used in the default dialects' metaschemas, so that performance penalty is going to be paid everywhere essentially, for any schemas. Way better is finally addressing that unfortunate truth (needing state during validation now), which will change how evaluating unevaluatedProperties looks in the codebase.

I'll re-evaluate after 4.18 is out to decide, so I won't close this one way or the other yet -- so acking that I saw this, and benchmarking some schemas certainly couldn't hurt, but don't feel offended if I close.

@ikonst
Copy link
Contributor Author

ikonst commented Mar 27, 2023

@Julian

I'm confused about what it does right now, though.

Given my example, it'll be validating instance {"foo": 42} against schema {"^foo": {"type": "number"}} that doesn't look like a valid schema, and in fact valid for all inputs. For sake of argument, if it's valid for all inputs, why call is_valid at all?

@Julian
Copy link
Member

Julian commented Mar 27, 2023

Oh I see this isn't related to #1068 -- I hadn't looked at the example carefully and assumed it was what we were previously discussing. OK, I'll still probably not be able to focus on this until after 4.18, but if there's some actual bug and this doesn't add new performance impact that's a lot more likely to be mergeable.

@ikonst
Copy link
Contributor Author

ikonst commented Mar 28, 2023

I think it's a pretty straightforward change (what's there right now looks like a mix-up).

Then again, if you want to validate less, maybe instead of this PR you'd just want to remove the is_valids since the tests seem to pass even in their absence:
#1075

@ikonst ikonst closed this Mar 28, 2023
@ikonst
Copy link
Contributor Author

ikonst commented Mar 28, 2023

Replaced by #1075

@ikonst ikonst deleted the 2023-03-26-unevaluatedProperties-patternProperties branch March 28, 2023 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants