-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Non-iterable values get passed as [] to @pre_load @validates_schema et al. #164
Comments
Hmm, I think this is because of #267 ( |
@tuukkamustonen @sloria I've found the test which I think related to the issue: webargs/src/webargs/testing.py Lines 96 to 97 in cfe9c4a
The question is why invalid input type is implicitly converted into an empty list? Shouldn't the method return a response with the error "Invalid input type" ? |
Is this fixed in webargs 6 beta? |
Tried to check it, but so many things have changed and I don't have time to go deeper into it right now. |
With from marshmallow import Schema, fields
from webargs.flaskparser import FlaskParser
from unittest.mock import Mock
class Foo(Schema):
foo = fields.Str()
parser = FlaskParser()
req = Mock()
req.mimetype = 'application/json'
req.get_data = lambda *_, **__: '{"foo": 1}' # or any non-iterable
parser.parse(Foo(many=True), req=req, location='json') I get
I guess this means it is fixed. |
@lafrech I got the same result. But I don't think that the original issue is necessarily fixed. The issue is about But these decorators have changed, too, I'm not sure how they work these days, had to stop there. |
What about import marshmallow as ma
from marshmallow import Schema, fields
from webargs.flaskparser import FlaskParser
from unittest.mock import Mock
class Foo(Schema):
# Both raise
@ma.pre_load
def test_pre_load(self, data, **kwargs):
print(data)
return data
@ma.validates_schema(pass_original=True)
def test_validates_schema(self, data, original_data, **kwargs):
print(data)
print(original_data)
return data
foo = fields.Str()
parser = FlaskParser()
req = Mock()
req.mimetype = 'application/json'
req.get_data = lambda *_, **__: '{"foo": "1"}' # or any non-iterable
parser.parse(Foo(), req=req, location='json')
|
The problem was with import marshmallow as ma
from marshmallow import Schema, fields
from webargs.flaskparser import FlaskParser
from unittest.mock import Mock
class Foo(Schema):
# Both raise
@ma.pre_load(pass_many=True)
def test_pre_load(self, data, **kwargs):
print('@pre_load data:', data)
return data
@ma.validates_schema(pass_original=True)
def test_validates_schema(self, data, original_data, **kwargs):
print('@validates_schema data:', data)
print('@validates_schema original_data:', original_data)
return data
foo = fields.Str()
parser = FlaskParser()
req = Mock()
req.mimetype = 'application/json'
req.get_data = lambda *_, **__: '{"foo": "1"}' # or any non-iterable
parser.parse(Foo(many=True), req=req, location='json') Prints:
So
So yeah, let's assume this fixed. |
Thanks for looking into this. |
With:
@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...?The text was updated successfully, but these errors were encountered: