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/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 -------------- 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):