Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webargs to 8.4.0 #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pyup-bot
Copy link
Collaborator

@pyup-bot pyup-bot commented Jan 7, 2024

This PR updates webargs from 2.0.0 to 8.4.0.

Changelog

8.4.0

******************

Features:

* Add a new class attribute, ``empty_value`` to ``DelimitedList`` and
``DelimitedTuple``, with a default of ``""``.
This controls the value deserialized when an empty string is seen.

``empty_value`` can be used to handle types other than strings more gracefully, e.g.

.. code-block:: python

 from webargs import fields


 class IntList(fields.DelimitedList):
     empty_value = 0


 myfield = IntList(fields.Int())

.. note::

 ``empty_value`` will be changing in webargs v9.0 to be ``missing`` by
 default. This will allow use of fields with ``load_default`` to specify
 handling of the empty value.

* The rule for default argument names has been made configurable by overriding
the ``get_default_arg_name`` method. This is described in the argument
passing documentation.

Other changes:

* Drop support for Python 3.7, which is EOL.
* Type annotations for ``FlaskParser`` have been improved.

8.3.0

******************

Features:

* ``webargs.Parser`` now inherits from ``typing.Generic`` and is parametrizable
over the type of the request object. Various framework-specific parsers are
parametrized over their relevant request object classes.

* ``webargs.Parser`` and its subclasses now support passing arguments as a
single keyword argument without expanding the parsed data into its
components. For more details, see advanced docs on
``Argument Passing and arg_name``.

Other changes:

* Type annotations have been improved to allow ``Mapping`` for dict-like
schemas where previously ``dict`` was used. This makes the type covariant
rather than invariant (:issue:`836`).

* Test against Python 3.11 (:pr:`787`).

8.2.0

******************

Features:

* A new method, ``webargs.Parser.async_parse``, can be used for async-aware
parsing from the base parser class. This can handle async location loader
functions and async error handlers.

* ``webargs.Parser.use_args`` and ``use_kwargs`` can now be used to decorate
async functions, and will use  ``async_parse`` if the decorated function is
also async. They will call the non-async ``parse`` method when used to
decorate non-async functions.

* As a result of the changes to ``webargs.Parser``, ``FlaskParser``,
``DjangoParser``, and ``FalconParser`` now all support async views.
Thanks :user:`Isira-Seneviratne` for the initial PR.

Changes:

* The implementation of ``AsyncParser`` has changed. Now that
``webargs.Parser`` has built-in support for async usage, the primary
purpose of ``AsyncParser`` is to redefine ``parse`` as an alias for
``async_parse``

* Set ``python_requires>=3.7.2`` in package metadata (:pr:`692`).
Thanks :user:`kasium` for the PR.

8.1.0

******************

Bug fixes:

* Fix publishing type hints per `PEP-561 <https://www.python.org/dev/peps/pep-0561/>`_.
(:pr:`650`).
* Add DelimitedTuple to fields.__all__ (:pr:`678`).
* Narrow type of ``argmap`` from ``Mapping`` to ``Dict`` (:pr:`682`).

Other changes:

* Test against Python 3.10 (:pr:`647`).
* Drop support for Python 3.6 (:pr:`673`).
* Address distutils deprecation warning in Python 3.10 (:pr:`652`).
Thanks :user:`kkirsche` for the PR.
* Use postponed evaluation of annotations (:pr:`663`).
Thanks :user:`Isira-Seneviratne` for the PR.
* Pin mypy version in tox (:pr:`674`).
* Improve type annotations for ``__version_info__`` (:pr:`680`).

8.0.1

******************

Bug fixes:

* Fix "``DelimitedList`` deserializes empty string as ``['']``" (:issue:`623`).
Thanks :user:`TTWSchell` for reporting and for the PR.

Other changes:

* New documentation theme with `furo`. Thanks to :user:`pradyunsg` for writing
furo!
* Webargs has a new logo. Thanks to :user:`michaelizergit`! (:issue:`312`)
* Don't build universal wheels. We don't support Python 2 anymore.
(:pr:`632`)
* Make the build reproducible (:pr:`631`).

8.0.0

******************

Features:

* Add `Parser.pre_load` as a method for allowing users to modify data before
schema loading, but without redefining location loaders. See advanced docs on
`Parser pre_load` for usage information. (:pr:`583`)

* *Backwards-incompatible*: ``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. If
``is_multiple`` is not set or is set to ``None``, webargs will check if the
field is an instance of ``List`` or ``Tuple``. (:issue:`563`)

* A new attribute on ``Parser`` objects, ``Parser.KNOWN_MULTI_FIELDS`` can be
used to set fields which should be detected as ``is_multiple=True`` even when
the attribute is not set (:pr:`592`).

See docs on "Multi-Field Detection" for more details.

Bug fixes:

* ``Tuple`` field now behaves as a "multiple" field (:pr:`585`).

7.0.1

******************

Bug fixes:

* Fix `DelimitedList` and `DelimitedTuple` to pass additional keyword arguments
through their `_serialize` methods to the child fields and fix type checking
on these classes. (:issue:`569`)
Thanks to :user:`decaz` for reporting.

7.0.0

******************

Changes:

* *Backwards-incompatible*: Drop support for webapp2 (:pr:`565`).

* Add type annotations to `Parser` class, `DelimitedList`, and
`DelimitedTuple`. (:issue:`566`)

7.0.0b2

********************

Features:

* `DjangoParser` now supports the `headers` location. (:issue:`540`)

* `FalconParser` now supports a new `media` location, which uses
Falcon's `media` decoding. (:issue:`253`)

`media` behaves very similarly to the `json` location but also supports any
registered media handler. See the
`Falcon documentation on media types
<https://falcon.readthedocs.io/en/stable/api/media.html>`_ for more details.

Changes:

* `FalconParser` defaults to the `media` location instead of `json`. (:issue:`253`)
* Test against Python 3.9 (:pr:`552`).
* *Backwards-incompatible*: Drop support for Python 3.5 (:pr:`553`).

7.0.0b1

********************

Refactoring:

* *Backwards-incompatible*: Remove support for marshmallow2 (:issue:`539`)

* *Backwards-incompatible*: Remove `dict2schema`

Users desiring the `dict2schema` functionality may now rely upon
`marshmallow.Schema.from_dict`. Rewrite any code using `dict2schema` like so:

.. code-block:: python

 import marshmallow as ma

  webargs 6.x and older
 from webargs import dict2schema

 myschema = dict2schema({"q1", ma.fields.Int()})

  webargs 7.x
 myschema = ma.Schema.from_dict({"q1", ma.fields.Int()})

Features:

* Add ``unknown`` as a parameter to ``Parser.parse``, ``Parser.use_args``,
``Parser.use_kwargs``, and parser instantiation. When set, it will be passed
to ``Schema.load``. When not set, the value passed will depend on the parser's
settings. If set to ``None``, the schema's default behavior will be used (i.e.
no value is passed to ``Schema.load``) and parser settings will be ignored.

This allows usages like

.. code-block:: python

 import marshmallow as ma


 parser.use_kwargs(
     {"q1": ma.fields.Int(), "q2": ma.fields.Int()}, location="query", unknown=ma.EXCLUDE
 )
 def foo(q1, q2):
     ...

* Defaults for ``unknown`` may be customized on parser classes via
``Parser.DEFAULT_UNKNOWN_BY_LOCATION``, which maps location names to values
to use.

Usages are varied, but include

.. code-block:: python

 import marshmallow as ma
 from webargs.flaskparser import FlaskParser

  as well as...
 class MyParser(FlaskParser):
     DEFAULT_UNKNOWN_BY_LOCATION = {"query": ma.INCLUDE}


 parser = MyParser()

Setting the ``unknown`` value for a Parser instance has higher precedence. So

.. code-block:: python

 parser = MyParser(unknown=ma.RAISE)

will always pass ``RAISE``, even when the location is ``query``.

* By default, webargs will pass ``unknown=EXCLUDE`` for all locations except
for request bodies (``json``, ``form``, and ``json_or_form``) and path
parameters. Request bodies and path parameters will pass ``unknown=RAISE``.
This behavior is defined by the default value for
``DEFAULT_UNKNOWN_BY_LOCATION``.

Changes:

* Registered `error_handler` callbacks are required to raise an exception.
If a handler is invoked and no exception is raised, `webargs` will raise
a `ValueError` (:issue:`527`)

6.1.1

******************

Bug fixes:

* Failure to validate flask headers would produce error data which contained
tuples as keys, and was therefore not JSON-serializable. (:issue:`500`)
These errors will now extract the headername as the key correctly.
Thanks to :user:`shughes-uk` for reporting.

6.1.0

******************

Features:

* Add ``fields.DelimitedTuple`` when using marshmallow 3. This behaves as a
combination of ``fields.DelimitedList`` and ``marshmallow.fields.Tuple``. It
takes an iterable of fields, plus a delimiter (defaults to ``,``), and parses
delimiter-separated strings into tuples. (:pr:`509`)

* Add ``__str__`` and ``__repr__`` to MultiDictProxy to make it easier to work
with (:pr:`488`)

Support:

* Various docs updates (:pr:`482`, :pr:`486`, :pr:`489`, :pr:`498`, :pr:`508`).
Thanks :user:`lefterisjp`, :user:`timgates42`, and :user:`ugultopu` for the PRs.

6.0.0

******************

Features:

* ``FalconParser``: Pass request content length to ``req.stream.read`` to
provide compatibility with ``falcon.testing`` (:pr:`477`).
Thanks :user:`suola` for the PR.

* *Backwards-incompatible*: Factorize the ``use_args`` / ``use_kwargs`` branch
in all parsers. When ``as_kwargs`` is ``False``, arguments are now
consistently appended to the arguments list by the ``use_args`` decorator.
Before this change, the ``PyramidParser`` would prepend the argument list on
each call to ``use_args``. Pyramid view functions must reverse the order of
their arguments. (:pr:`478`)

6.0.0b8

********************

Refactoring:

* *Backwards-incompatible*: Use keyword-only arguments (:pr:`472`).

6.0.0b7

********************

Features:

* *Backwards-incompatible*: webargs will rewrite the error messages in
ValidationErrors to be namespaced under the location which raised the error.
The `messages` field on errors will therefore be one layer deeper with a
single top-level key.

6.0.0b6

********************

Refactoring:

* Remove the cache attached to webargs parsers. Due to changes between webargs
v5 and v6, the cache is no longer considered useful.

Other changes:

* Import ``Mapping`` from ``collections.abc`` in pyramidparser.py (:pr:`471`).
Thanks :user:`tirkarthi` for the PR.

6.0.0b5

********************

Refactoring:

* *Backwards-incompatible*: `DelimitedList` now requires that its input be a
string and always serializes as a string. It can still serialize and deserialize
using another field, e.g. `DelimitedList(Int())` is still valid and requires
that the values in the list parse as ints.

6.0.0b4

********************

Bug fixes:

* :cve:`CVE-2020-7965`: Don't attempt to parse JSON if request's content type is mismatched
(bugfix from 5.5.3).

6.0.0b3

********************

Features:

* *Backwards-incompatible*: Support Falcon 2.0. Drop support for Falcon 1.x
(:pr:`459`). Thanks :user:`dodumosu` and :user:`Nateyo` for the PR.

6.0.0b2

********************

Other changes:

* *Backwards-incompatible*: Drop support for Python 2 (:issue:`440`).
Thanks :user:`hugovk` for the PR.

6.0.0b1

********************

Features:

* *Backwards-incompatible*: Schemas will now load all data from a location, not
only data specified by fields. As a result, schemas with validators which
examine the full input data may change in behavior. The `unknown` parameter
on schemas may be used to alter this. For example,
`unknown=marshmallow.EXCLUDE` will produce a behavior similar to webargs v5.

Bug fixes:

* *Backwards-incompatible*: All parsers now require the Content-Type to be set
correctly when processing JSON request bodies. This impacts ``DjangoParser``,
``FalconParser``, ``FlaskParser``, and ``PyramidParser``

Refactoring:

* *Backwards-incompatible*: Schema fields may not specify a location any
longer, and `Parser.use_args` and `Parser.use_kwargs` now accept `location`
(singular) instead of `locations` (plural). Instead of using a single field or
schema with multiple `locations`, users are recommended to make multiple
calls to `use_args` or `use_kwargs` with a distinct schema per location. For
example, code should be rewritten like this:

.. code-block:: python

  webargs 5.x and older
 parser.use_args(
     {
         "q1": ma.fields.Int(location="query"),
         "q2": ma.fields.Int(location="query"),
         "h1": ma.fields.Int(location="headers"),
     },
     locations=("query", "headers"),
 )
 def foo(q1, q2, h1):
     ...


  webargs 6.x
 parser.use_args({"q1": ma.fields.Int(), "q2": ma.fields.Int()}, location="query")
 parser.use_args({"h1": ma.fields.Int()}, location="headers")
 def foo(q1, q2, h1):
     ...

* The `location_handler` decorator has been removed and replaced with
`location_loader`. `location_loader` serves the same purpose (letting you
write custom hooks for loading data) but its expected method signature is
different. See the docs on `location_loader` for proper usage.

Thanks :user:`sirosen` for the PR!

5.5.3

******************

Bug fixes:

* :cve:`CVE-2020-7965`: Don't attempt to parse JSON if request's content type is mismatched.

5.5.2

******************

Bug fixes:

* Handle ``UnicodeDecodeError`` when parsing JSON payloads (:issue:`427`).
Thanks :user:`lindycoder` for the catch and patch.

5.5.1

******************

Bug fixes:

* Remove usage of deprecated ``Field.fail`` when using marshmallow 3.

5.5.0

******************

Support:

* Various docs updates (:pr:`414`, :pr:`421`).

Refactoring:

* Don't mutate ``globals()`` in ``webargs.fields`` (:pr:`411`).
* Use marshmallow 3's ``Schema.from_dict`` if available (:pr:`415`).

5.4.0

******************

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

******************

Bug fixes:

* marshmallow 3.0.0rc7 compatibility (:pr:`395`).

5.3.1

******************

Bug fixes:

* marshmallow 3.0.0rc6 compatibility (:pr:`384`).

5.3.0

******************

Features:

* Add `"path"` location to ``AIOHTTPParser``, ``FlaskParser``, and
``PyramidParser`` (:pr:`379`). Thanks :user:`zhenhua32` for the PR.
* Add ``webargs.__version_info__``.

5.2.0

******************

Features:

* Make the schema class used when generating a schema from a
dict overridable (:issue:`375`). Thanks :user:`ThiefMaster`.

5.1.3

******************

Bug fixes:

* :cve:`CVE-2019-9710`: Fix race condition between parallel requests when the cache is used
(:issue:`371`). Thanks :user:`ThiefMaster` for reporting and fixing.

5.1.2

******************

Bug fixes:

* Remove lingering usages of ``ValidationError.status_code``
(:issue:`365`). Thanks :user:`decaz` for reporting.
* Avoid ``AttributeError`` on Python<3.5.4 (:issue:`366`).
* Fix incorrect type annotations for ``error_headers``.
* Fix outdated docs (:issue:`367`). Thanks :user:`alexandersoto` for reporting.

5.1.1.post0

************************

* Include LICENSE in sdist (:issue:`364`).

5.1.1

******************

Bug fixes:

* Fix installing ``simplejson`` on Python 2 by
distributing a Python 2-only wheel (:issue:`363`).

5.1.0

******************

Features:

* Error handlers for `AsyncParser` classes may be coroutine functions.
* Add type annotations to `AsyncParser` and `AIOHTTPParser`.

Bug fixes:

* Fix compatibility with Flask<1.0 (:issue:`355`).
Thanks :user:`hoatle` for reporting.
* Address warning on Python 3.7 about importing from ``collections.abc``.

5.0.0

******************

Features:

* *Backwards-incompatible*: A 400 HTTPError is raised when an
invalid JSON payload is passed.  (:issue:`329`).
Thanks :user:`zedrdave` for reporting.

Other changes:

* *Backwards-incompatible*: `webargs.argmap2schema` is removed. Use
`webargs.dict2schema` instead.
* *Backwards-incompatible*: `webargs.ValidationError` is removed.
Use `marshmallow.ValidationError` instead.


.. code-block:: python

  <5.0.0
 from webargs import ValidationError


 def auth_validator(value):
      ...
     raise ValidationError("Authentication failed", status_code=401)


 use_args({"auth": fields.Field(validate=auth_validator)})
 def auth_view(args):
     return jsonify(args)


  >=5.0.0
 from marshmallow import ValidationError


 def auth_validator(value):
      ...
     raise ValidationError("Authentication failed")


 use_args({"auth": fields.Field(validate=auth_validator)}, error_status_code=401)
 def auth_view(args):
     return jsonify(args)


* *Backwards-incompatible*: Missing arguments will no longer be filled
in when using ``use_kwargs`` (:issue:`342,307,252`). Use ``**kwargs``
to account for non-required fields.

.. code-block:: python

  <5.0.0
 use_kwargs(
     {"first_name": fields.Str(required=True), "last_name": fields.Str(required=False)}
 )
 def myview(first_name, last_name):
      last_name is webargs.missing if it's missing from the request
     return {"first_name": first_name}


  >=5.0.0
 use_kwargs(
     {"first_name": fields.Str(required=True), "last_name": fields.Str(required=False)}
 )
 def myview(first_name, **kwargs):
      last_name will not be in kwargs if it's missing from the request
     return {"first_name": first_name}


* `simplejson <https://pypi.org/project/simplejson/>`_ is now a required
dependency on Python 2 (:pr:`334`).
This ensures consistency of behavior across Python 2 and 3.

4.4.1

******************

Bug fixes:

* Remove usages of ``argmap2schema`` from ``fields.Nested``,
``AsyncParser``, and ``PyramidParser``.

4.4.0

******************

* *Deprecation*: ``argmap2schema`` is deprecated in favor of
``dict2schema`` (:pr:`352`).

4.3.1

******************

* Add ``force_all`` param to ``PyramidParser.use_args``.
* Add warning about missing arguments to ``AsyncParser``.

4.3.0

******************

* *Deprecation*: Add warning about missing arguments getting added
to parsed arguments dictionary (:issue:`342`). This behavior will be
removed in version 5.0.0.

4.2.0

******************

Features:

* Add ``force_all`` argument to ``use_args`` and ``use_kwargs``
(:issue:`252`, :issue:`307`). Thanks :user:`piroux` for reporting.
* *Deprecation*: The ``status_code`` and ``headers`` arguments to ``ValidationError``
are deprecated. Pass ``error_status_code`` and ``error_headers`` to
`Parser.parse`, `Parser.use_args`, and `Parser.use_kwargs` instead.
(:issue:`327`, :issue:`336`).
* Custom error handlers receive ``error_status_code`` and ``error_headers`` arguments.
(:issue:`327`).

.. code-block:: python

  <4.2.0
 parser.error_handler
 def handle_error(error, req, schema):
     raise CustomError(error.messages)


 class MyParser(FlaskParser):
     def handle_error(self, error, req, schema):
          ...
         raise CustomError(error.messages)


  >=4.2.0
 parser.error_handler
 def handle_error(error, req, schema, status_code, headers):
     raise CustomError(error.messages)


  OR


 parser.error_handler
 def handle_error(error, **kwargs):
     raise CustomError(error.messages)


 class MyParser(FlaskParser):
     def handle_error(self, error, req, schema, status_code, headers):
          ...
         raise CustomError(error.messages)

      OR

     def handle_error(self, error, req, **kwargs):
          ...
         raise CustomError(error.messages)

Legacy error handlers will be supported until version 5.0.0.

4.1.3

******************

Bug fixes:

* Fix bug in ``AIOHTTParser`` that prevented calling
``use_args`` on the same view function multiple times (:issue:`273`).
Thanks to :user:`dnp1` for reporting and :user:`jangelo` for the fix.
* Fix compatibility with marshmallow 3.0.0rc1 (:pr:`330`).

4.1.2

******************

Bug fixes:

* Fix serialization behavior of ``DelimitedList`` (:pr:`319`).
Thanks :user:`lee3164` for the PR.

Other changes:

* Test against Python 3.7.

4.1.1

******************

Bug fixes:

* Fix bug in ``AIOHTTPParser`` that caused a ``JSONDecode`` error
when parsing empty payloads (:issue:`229`). Thanks :user:`explosic4`
for reporting and thanks user :user:`kochab` for the PR.

4.1.0

******************

Features:

* Add ``webargs.testing`` module, which exposes ``CommonTestCase``
to third-party parser libraries (see comments in :pr:`287`).

4.0.0

******************

Features:

* *Backwards-incompatible*: Custom error handlers receive the
`marshmallow.Schema` instance as the third argument. Update any
functions decorated with `Parser.error_handler` to take a ``schema``
argument, like so:

.. code-block:: python

  3.x
 parser.error_handler
 def handle_error(error, req):
     raise CustomError(error.messages)


  4.x
 parser.error_handler
 def handle_error(error, req, schema):
     raise CustomError(error.messages)


See `marshmallow-code/marshmallow840 (comment) <https://github.com/marshmallow-code/marshmallow/issues/840#issuecomment-403481686>`_
for more information about this change.

Bug fixes:

* *Backwards-incompatible*: Rename ``webargs.async`` to
``webargs.asyncparser`` to fix compatibility with Python 3.7
(:issue:`240`). Thanks :user:`Reskov` for the catch and patch.


Other changes:

* *Backwards-incompatible*: Drop support for Python 3.4 (:pr:`243`). Python 2.7 and
>=3.5 are supported.
* *Backwards-incompatible*: Drop support for marshmallow<2.15.0.
marshmallow>=2.15.0 and >=3.0.0b12 are officially supported.
* Use `black <https://github.com/ambv/black>`_ with `pre-commit <https://pre-commit.com/>`_
for code formatting (:pr:`244`).

3.0.2

******************

Bug fixes:

* Fix compatibility with marshmallow 3.0.0b12 (:pr:`242`). Thanks :user:`lafrech`.

3.0.1

******************

Bug fixes:

* Respect `Parser.DEFAULT_VALIDATION_STATUS` when a `status_code` is not
explicitly passed to `ValidationError` (:issue:`180`). Thanks :user:`foresmac` for
finding this.

Support:

* Add "Returning HTTP 400 Responses" section to docs (:issue:`180`).

3.0.0

******************

Changes:

* *Backwards-incompatible*: Custom error handlers receive the request object as the second
argument. Update any functions decorated with ``Parser.error_handler`` to take a `req` argument, like so:

.. code-block:: python

  2.x
 parser.error_handler
 def handle_error(error):
     raise CustomError(error.messages)


  3.x
 parser.error_handler
 def handle_error(error, req):
     raise CustomError(error.messages)

* *Backwards-incompatible*: Remove unused ``instance`` and ``kwargs`` arguments of ``argmap2schema``.
* *Backwards-incompatible*: Remove ``Parser.load`` method (``Parser`` now calls ``Schema.load`` directly).

These changes shouldn't affect most users. However, they might break custom parsers calling these methods. (:pr:`222`)

* Drop support for aiohttp<3.0.0.

2.1.0

******************

Features:

* Respect ``data_key`` field argument (in marshmallow 3). Thanks
:user:`lafrech`.
Links

@pyup-bot pyup-bot mentioned this pull request Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant