Inconsistent behavior in passing request fields to Schema.load (many=True vs many=False)
See original GitHub issueWith 4.0.0
(and marshmallow 3.0.0b13
):
class Sch(Schema):
foo = fields.Str()
parser = FlaskParser()
req = Mock()
req.mimetype = 'application/json'
req.get_json = lambda *args, **kwargs: [{'extra': 1}]
with pytest.raises(UnprocessableEntity) as e:
parser.parse(Foo(many=True), req=req, locations=('json', ))
assert e.value.exc.messages == {0: {'extra': ['Unknown field.']}}
req.get_json = lambda *args, **kwargs: {'extra': 1}
parser.parse(Foo(), req=req, locations=('json', ))
So the with many=True
the extra key is actually passed to Schema.load()
(which can then raise ValidationError
because unknown
defaults to RAISE
) but with many=False
it is passed onwards. I think it’s confusing.
#267 would fix this.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
marshmallow - Read the Docs
Note: If you pass in a string field name to only, only a single value (or flat list of values if many=True) will...
Read more >Source code for marshmallow_jsonapi.fields
Schema ` to determine which fields should be formatted as relationship objects. See: http://jsonapi.org/format/#document-resource-object-relationships """ ...
Read more >marshmallow - Bountysource
In order to iterate over a schema's fields in the order in which it was defined, you have to add a class Meta:...
Read more >Inconsistent Behavior for IMPORT with RENAME SCHEMA ...
Hello all, I'm looking into methods to help automate initialization of schemas with a base catalog objects in HANA Cloud and the strategy ......
Read more >OASIS Specification Template
These applications know which methods to call or fields to access on the Data Objects they ... The end user sends a request...
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
Fixed.
Just a minor “correction”:
The latter case, with
many=False
actually failed with just{"extra": 1}
not[{"extra": 1}]
(as in your code above).But both those now raise error properly, so yeah it’s fixed.