Skip to content

Commit

Permalink
Merge pull request #595 from marshmallow-code/body_args_unknown_defau…
Browse files Browse the repository at this point in the history
…lt_none

Modify unknown default to `None` for json, form and json_or_form
  • Loading branch information
lafrech authored Mar 15, 2021
2 parents e5aff1f + 3c179c1 commit 8e6e68a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Changelog
---------

7.1.0 (Unreleased)
8.0.0 (Unreleased)
******************

Features:

* ``unknown`` defaults to `None` for body locations (`json`, `form` and
`json_or_form`) (:issue:`580`).

* Detection of fields as "multi-value" for unpacking lists from multi-dict
types is now extensible with the `is_multiple` attribute. If a field sets
`is_multiple = True` it will be detected as a multi-value field.
Expand Down
2 changes: 1 addition & 1 deletion src/webargs/aiohttpparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _find_exceptions() -> None:
class AIOHTTPParser(AsyncParser):
"""aiohttp request argument parser."""

DEFAULT_UNKNOWN_BY_LOCATION = {
DEFAULT_UNKNOWN_BY_LOCATION: typing.Dict[str, typing.Optional[str]] = {
"match_info": RAISE,
"path": RAISE,
**core.Parser.DEFAULT_UNKNOWN_BY_LOCATION,
Expand Down
8 changes: 4 additions & 4 deletions src/webargs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class Parser:
DEFAULT_LOCATION: str = "json"
#: Default value to use for 'unknown' on schema load
# on a per-location basis
DEFAULT_UNKNOWN_BY_LOCATION: typing.Dict[str, str] = {
"json": ma.RAISE,
"form": ma.RAISE,
"json_or_form": ma.RAISE,
DEFAULT_UNKNOWN_BY_LOCATION: typing.Dict[str, typing.Optional[str]] = {
"json": None,
"form": None,
"json_or_form": None,
"querystring": ma.EXCLUDE,
"query": ma.EXCLUDE,
"headers": ma.EXCLUDE,
Expand Down
4 changes: 3 additions & 1 deletion src/webargs/flaskparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def user_detail(args, uid):
uid=uid, per_page=args["per_page"]
)
"""
import typing

import flask
from werkzeug.exceptions import HTTPException

Expand Down Expand Up @@ -49,7 +51,7 @@ def is_json_request(req):
class FlaskParser(core.Parser):
"""Flask request argument parser."""

DEFAULT_UNKNOWN_BY_LOCATION = {
DEFAULT_UNKNOWN_BY_LOCATION: typing.Dict[str, typing.Optional[str]] = {
"view_args": ma.RAISE,
"path": ma.RAISE,
**core.Parser.DEFAULT_UNKNOWN_BY_LOCATION,
Expand Down
3 changes: 2 additions & 1 deletion src/webargs/pyramidparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def hello_world(request, args):
server.serve_forever()
"""
import functools
import typing
from collections.abc import Mapping

from webob.multidict import MultiDict
Expand All @@ -43,7 +44,7 @@ def is_json_request(req):
class PyramidParser(core.Parser):
"""Pyramid request argument parser."""

DEFAULT_UNKNOWN_BY_LOCATION = {
DEFAULT_UNKNOWN_BY_LOCATION: typing.Dict[str, typing.Optional[str]] = {
"matchdict": ma.RAISE,
"path": ma.RAISE,
**core.Parser.DEFAULT_UNKNOWN_BY_LOCATION,
Expand Down

0 comments on commit 8e6e68a

Please sign in to comment.