Non-iterable values get passed as [] to @pre_load @validates_schema et al.
See original GitHub issueWith:
class Foo(StrictSchema):
foo = fields.Str()
parser = FlaskParser()
req = Mock()
req.mimetype = 'application/json'
req.get_json = lambda *_, **__: {'foo': 1} # or any non-iterable
parser.parse(Foo(strict=True, many=True), req=req, locations=('json', ))
@pre_load(pass_original=True)
@validate_schema(pass_original=True)
get []
as original value, instead of {'foo': 1}
.
This makes it impossible to record errors about invalid base type / extra fields.
This happens for any non-iterable non-string non-mapping value.
The code that’s related to this is in get_value()
at https://github.com/sloria/webargs/blob/dev/webargs/core.py#L130-L132. Not yet sure what all that processing really does, but could that function return the data as is…?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
JSON Schema validation - both values should not be false at ...
To validate this, we need two schemas: one to validate value1 is true and value2 is true . Then we put both of...
Read more >Extending Schemas — marshmallow 3.19.0 documentation
The method receives the ValidationError and the original input data to be deserialized.
Read more >jquense/yup: Dead simple Object schema validation - GitHub
Yup is a schema builder for runtime value parsing and validation. ... Watch out! values are not guaranteed to be valid types in...
Read more >Validation Rules — Cerberus is a lightweight and extensible ...
This rule takes a collectionsabc.Container of allowed values. Validates the target value if the value is in the allowed values. If the target...
Read more >Validating Data With JSON-Schema, Part 2 - Code
JSON-pointers can be used not only in JSON-schemas. ... One approach is to have all connected schemas preloaded like we had in the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for looking into this.
The problem was with
many=True
. Added that and made@pre_load
takepass_many=True
:Prints:
So
@pre_load
works as expected, it now gets the original payload passed in, as should. This didn’t work earlier so it’s now fixed.@validates_schema
never evaluates now, because exception is raised before it. I don’t know if this is how it should work by design, but I guess yes. IIRC, the problem with earlier versions was that they failed to ensure that given payload was actually an array, whenmany=True
was passed in. Now it seems to do that, and error gets risen. I think current logic is good.So yeah, let’s assume this fixed.