Skip to content
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

[Webargs 6.0+] Validation middleware does not support unknown field behavior specified with a Marshmallow 3 schema #111

Closed
pzhang65 opened this issue Aug 27, 2021 · 3 comments · Fixed by #112

Comments

@pzhang65
Copy link
Contributor

pzhang65 commented Aug 27, 2021

Currently the validation middleware relies on webargs to parse and validate request object. Problem is webargs 5.x does not fully support marshmallow 3.

Consider this example by @lafrech in marshmallow-code/webargs#267

def test_parser_nested_unknown(web_request):
    class MyNestedSchema(Schema):
        i = fields.Int()

    class MySchema(Schema):
        n = fields.Nested(MyNestedSchema)

    parser = MockRequestParser()
    web_request.json = {
        'n': {
            'i': 12,
            #'j': 12,
        },
        'o': 12,
    }
    parsed = parser.parse(MySchema, web_request)
    print(parsed)
    # {'n': {'i': 12}}

Uncomment the 'j': 12 line and you get

marshmallow.exceptions.ValidationError: {'n': {'j': ['Unknown field.']}}

while the 'o': 12 line, top-level, triggers no error.

At the top level, webargs is responsible for picking the attributes, so it doesn't notice the unknown ones. Nested schemas are managed by marshmallow so things go as expected.

Flask-apispec has also dropped marshmallow 2 by updating to webargs 6.0+
jmcarp/flask-apispec#195

Is there any plans to support webargs 6.0+?
I'd be willing to work on this issue if the project is still being maintained.

@ghost
Copy link

ghost commented Aug 28, 2021

I've also run into this issue. Let me know if you end up forking this lib

@maximdanilchenko
Copy link
Owner

@pzhang65 hey!

It would be great if you will do the work. I've had a lot of work on another projects recently, so I had not enough time for that library. But it is still in support status and I have plans on it, I will be more active starting from next week.
If you make a PR I'll do the rest to release it as fast as I can.

@pzhang65
Copy link
Contributor Author

@maximdanilchenko any news on a package release with my PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants