Cast form values when matching allOf subschemas (#1212)#1213
Open
apoorvdarshan wants to merge 1 commit into
Open
Cast form values when matching allOf subschemas (#1212)#1213apoorvdarshan wants to merge 1 commit into
apoorvdarshan wants to merge 1 commit into
Conversation
For application/x-www-form-urlencoded requests, iter_any_of_schemas casts scalar form values (which always arrive as strings) before validating each subschema, but iter_all_of_schemas did not. An allOf part containing a non-string field (boolean/integer/object) therefore failed validation against the raw string value and was silently dropped (only a 'invalid allOf schema found' warning), losing every field in that part. Give iter_all_of_schemas the same optional caster as iter_any_of_schemas and pass it from the media-type deserializer. Fixes python-openapi#1212.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1212. For
application/x-www-form-urlencodedrequests, anallOfsubschema that contains a non-string field (boolean, integer, object) is silently dropped — every field in that part disappears from the result, with only alog.warning("invalid allOf schema found")and an emptyresult.errors.Cause
Form values always arrive as strings.
iter_any_of_schemasalready takes an optionalcasterand coerces the value before validating each subschema (added for exactly this form-encoded case), butiter_all_of_schemasdid not — so it validated the raw string value against the boolean/integer field, failed, and skipped the whole subschema.Fix
Give
iter_all_of_schemasthe same optionalcasterparameter and casting logic asiter_any_of_schemas, and passcaster=self.schema_casterfromiter_composed_all_of_schemasin the media-type deserializer (mirroring the existinganyOfcall).Now the example yields
{'enabled': True, 'label': 'hello', 'name': 'widget'}.Tests
test_urlencoded_allof_non_string_field; it fails onmaster(fields dropped, warning logged) and passes here.tests/unit(excluding contrib/templating suites that need optional deps unrelated to this change) is green — 571 passed;ruffandblackclean.Disclosure: prepared with AI assistance; reviewed and verified locally.