-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
JSON schema: fix extra parameter handling #7810
JSON schema: fix extra parameter handling #7810
Conversation
Hmm. The naive fix here seems to be broken by there being a field in ConfigDict that means the same thing but is currently called |
The core schema for typed dicts has an "extra_behavior" key for checking whether additional unspecified keys are allowed, but the JSON schema generator ignores this and only checks the configuration dict. Have the JSON schema generator check both places, and prefer the value set in the core schema over the one in the config dictionary if both are present. Fixes pydantic#7809.
e144602
to
79b130e
Compare
Okay, I think that's good. Please review! I've not managed to contrive a scenario where both the config value and the schema value are set, so that isn't included in the new tests, but the tests do cover checking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM at a first glance. @me-and, thanks so much for your contribution 🌟.
@davidhewitt, could you give this a review as well?
The tests look good. Could you simplify the 3 tests you added a bit by using |
Please update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me, just one performance suggestion!
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Looks fine for now. I see you modeled this after other tests that were already present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the contribution 🥳
Ah, fantastic, got to it before I managed to. Thank you @sydney-runkle! |
Sure thing, thanks for the help! 😄 |
Change Summary
The core schema for typed dicts uses the "extra_behavior" key to determine whether additional unspecified keys are allowed in the dict; update the JSON schema generation to expect that, rather than to look for the non-existent "extra" key.
Related issue number
Fixes #7809.
Checklist
Selected Reviewer: @davidhewitt