Bug: Webargs 7 excludes unknown query args by default instead of raise exception
See original GitHub issueContext
One of my flask smorest API endpoints optionally allows a first_name
query param to be provided to filter the list of returned users:
@api.arguments(RetrieveUserQueryArgsSchema, location="query")
...
class RetrieveUserQueryArgsSchema(Schema):
"""
Defines the allowed query parameters for retrieving users.
"""
first_name = fields.String()
If an unknown param (e.g., “last_name”) is provided, an exception is normally raised.
Problem
However, after upgrading my webargs
pip dependency to version 7, I noticed by default it excludes unknown query params rather than raise an exception. This is breaking my automated tests.
Solution? After ensuring I have the latest version of flask, marshmallow, smorest and webargs, neither of these solutions work:
- explicitly setting
unknown = RAISE
as mentioned here - adding
DEFAULT_UNKNOWN_BY_LOCATION = {"query": ma.RAISE}
toRetrieveUserQueryArgsSchema
as mentioned here
What’s the correct fix for this? Perhaps my syntax isn’t quite right or is this a flask-smorest bug given that webargs 7 was released very recently (mid December)? Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Upgrading to Newer Releases - webargs 8.2.0 documentation
In this case, under webargs 7.0 the schema unknown setting of EXCLUDE would be ignored. Instead, unknown=RAISE would be used.
Read more >Changelog - webargs 8.2.0 documentation
By default, webargs will pass unknown=EXCLUDE for all locations except for request bodies ( json , form , and json_or_form ) and path...
Read more >Release 8.2.0 unknown - Webargs
Called if an error occurs while parsing args. By default, just logs and raises error. load_cookies(req: Request, schema: Schema). Load the ...
Read more >Advanced Usage - webargs 8.2.0 documentation
EXCLUDE except when the location is json , form , json_or_form , or path . In those cases, it uses unknown=marshmallow.RAISE instead.
Read more >Release 5.5.3 unknown - Webargs
Each parser has a default error handling method. ... DelimitedList to parse comma-separated lists in query parameters, e.g..
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
That’s a different problem from the OP. It can be done, but not in the way that you’ve phrased. If you want your sets of arguments merged, create a new schema with merges them – then you can set
unknown=RAISE
and get the restrictive behavior. You could create a new schema explicitly, with inheritance, or with a schema-factory.@lafrech, I think this issue is safe to close?
I’m happy to help add more doc – even if it duplicates webargs docs somewhat – but it looks like you’ve already taken care of the needful for this case.
I just updated the docs : https://flask-smorest.readthedocs.io/en/latest/arguments.html.