********************
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`)