From 0e94b6404193fe791610ac70bbb5de5560e70b06 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 23 Jul 2019 22:30:49 -0400 Subject: [PATCH 1/2] Add documentation for parsing lists in query strings --- docs/quickstart.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index fe2d42563..8437b18ac 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -195,6 +195,27 @@ Then decorate that function with :func:`Parser.error_handler ` to parse comma-separated +lists in query parameters, e.g. ``/?permissions=read,write`` + +.. code-block:: python + + from webargs import fields + + args = {"permissions": fields.DelimitedList(fields.Str())} + +If you expect repeated query parameters, e.g. ``/?repo=webargs&repo=marshmallow``, use +`fields.List ` instead. + +.. code-block:: python + + from webargs import fields + + args = {"repo": fields.List(fields.Str())} + Nesting Fields -------------- From cdfbc8b34b2df3734c16a9bdb3e41130c26963f6 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 23 Jul 2019 22:38:51 -0400 Subject: [PATCH 2/2] Use explicit type check instead of duck typing See https://github.com/marshmallow-code/webargs/issues/406#issuecomment-514379744 --- CHANGELOG.rst | 12 ++++++++++++ src/webargs/core.py | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2c9f5ca16..ade173963 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,18 @@ Changelog --------- +5.4.0 (unreleased) +****************** + +Changes: + +* Use explicit type check for `fields.DelimitedList` when deciding to + parse value with `getlist()` (`#406 (comment) `_ ). + +Support: + +* Add "Parsing Lists in Query Strings" section to docs (:issue:`406`). + 5.3.2 (2019-06-19) ****************** diff --git a/src/webargs/core.py b/src/webargs/core.py index b4b2fb374..2f4a5be72 100644 --- a/src/webargs/core.py +++ b/src/webargs/core.py @@ -65,7 +65,11 @@ class Meta(object): def is_multiple(field): """Return whether or not `field` handles repeated/multi-value arguments.""" - return isinstance(field, ma.fields.List) and not hasattr(field, "delimiter") + from webargs import fields # prevent circular import + + return isinstance(field, ma.fields.List) and not isinstance( + field, fields.DelimitedList + ) def get_mimetype(content_type):