Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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) <https://github.com/marshmallow-code/webargs/issues/406#issuecomment-514446228>`_ ).

Support:

* Add "Parsing Lists in Query Strings" section to docs (:issue:`406`).

5.3.2 (2019-06-19)
******************

Expand Down
21 changes: 21 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@ Then decorate that function with :func:`Parser.error_handler <webargs.core.Parse
def handle_error(error, req, schema, status_code, headers):
raise CustomError(error.messages)

Parsing Lists in Query Strings
------------------------------

Use `fields.DelimitedList <webargs.fields.DelimitedList>` 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 <marshmallow.fields.List>` instead.

.. code-block:: python

from webargs import fields

args = {"repo": fields.List(fields.Str())}

Nesting Fields
--------------

Expand Down
6 changes: 5 additions & 1 deletion src/webargs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably did this to avoid the circular import. Was a bad decision in retrospect.

from webargs import fields # prevent circular import

return isinstance(field, ma.fields.List) and not isinstance(
field, fields.DelimitedList
)


def get_mimetype(content_type):
Expand Down