Bug fixes:
argmap2schema
from fields.Nested
,
AsyncParser
, and PyramidParser
.force_all
param to PyramidParser.use_args
.AsyncParser
.Features:
force_all
argument to use_args
and use_kwargs
(#252, #307). Thanks @piroux for reporting.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.
(#327, #336).error_status_code
and error_headers
arguments.
(#327).# <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.
Bug fixes:
Bug fixes:
AIOHTTPParser
that caused a JSONDecode
error
when parsing empty payloads (#229). Thanks @explosic4
for reporting and thanks user @kochab for the PR.Features:
webargs.testing
module, which exposes CommonTestCase
to third-party parser libraries (see comments in #287).Features:
marshmallow.Schema
instance as the third argument. Update any
functions decorated with Parser.error_handler
to take a schema
argument, like so:# 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/marshmallow#840 (comment) for more information about this change.
Bug fixes:
webargs.async
to
webargs.asyncparser
to fix compatibility with Python 3.7
(#240). Thanks @Reskov for the catch and patch.Other changes:
Bug fixes:
Parser.DEFAULT_VALIDATION_STATUS
when a status_code
is not
explicitly passed to ValidationError
(#180). Thanks @foresmac for
finding this.Support:
Changes:
Parser.error_handler
to take a req
argument, like so:# 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)
instance
and kwargs
arguments of argmap2schema
.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. (#222)
Changes:
Features:
Deprecations:
Changes:
HTTPExceptions
raised with webargs.flaskparser.abort
will always
have the data
attribute, even if no additional keywords arguments
are passed (#184). Thanks @lafrech.Support:
Bug fixes:
AIOHTTPParser.use_args
when as_kwargs=True
is passed with a Schema
(#179). Thanks @Itayazolay.Features:
AIOHTTPParser
supports class-based views, i.e. aiohttp.web.View
(#177). Thanks @daniel98321.Features:
Support:
Bug fixes:
Bug fixes:
Other changes:
Bug fixes:
AsyncParser
. This fixes #146 for AIOHTTPParser
.DelimitedList
(#149). Thanks @psconnect-dev for reporting.Bug fixes:
marshmallow.missing
to original_data
when using marshmallow.validates_schema(pass_original=True)
(#146). Thanks @lafrech for reporting and for the fix.Other changes:
Bug fixes:
Features:
use_args
and use_kwargs
decorators add a reference to the undecorated function via the __wrapped__
attribute. This is useful for unit-testing purposes (#144). Thanks @EFF for the PR.Bug fixes:
Bug fixes:
ValidationError
object.# Before
@app.errorhandler(422)
def handle_validation_error(err):
return jsonify({"errors": err.messages}), 422
# After
@app.errorhandler(422)
def handle_validation_error(err):
# The marshmallow.ValidationError is available on err.exc
return jsonify({"errors": err.exc.messages}), 422
Bug fixes:
Bug fixes:
Bug fixes:
parser.parse
with a dict
in a view (#101). Thanks @frankslaughter for reporting.Support:
Features:
many=True
to a Schema
(#81). Thanks @frol.Bug fixes:
status_code
argument to ValidationError
(#85). This requires marshmallow>=2.7.0. Thanks @ParthGandhi for reporting.Support:
Bug fixes:
JSONDecodeError
raised when parsing non-JSON requests using default locations
(#80). Thanks @leonidumanskiy for reporting.application/vnd.api+json
.Features:
Parser.parse
, Parser.use_args
and Parser.use_kwargs
can take a Schema factory as the first argument (#73). Thanks @DamianHeard for the suggestion and the PR.Support:
Features:
AIOHTTPParser
(#71).webargs.async
module with AsyncParser
.Bug fixes:
Other changes:
FalconParser.use_args
, the parsed arguments dictionary will be positioned after the request and response arguments.DjangoParser.use_args
, the parsed arguments dictionary will be positioned after the request argument.Parser.get_request_from_view_args
gets passed a view function as its first argument.Features:
FalconParser
(#63).fields.DelimitedList
(#66). Thanks @jmcarp.TornadoParser
will parse json with simplejson
if it is installed.BottleParser
caches parsed json per-request for improved performance.No breaking changes. Yay!
Features:
TornadoParser
returns unicode strings rather than bytestrings (#41). Thanks @thomasboyt for the suggestion.Parser.get_default_request
and Parser.get_request_from_view_args
hooks to simplify Parser
implementations.webargs.core.get_value
takes a Field
as its last argument. Note: this is technically a breaking change, but this won’t affect most users since get_value
is only used internally by Parser
classes.Support:
examples/annotations_example.py
(demonstrates using Python 3 function annotations to define request arguments).Bug fixes:
validate
and force_all
params to PyramidParser.use_args
.The major change in this release is that webargs now depends on marshmallow for defining arguments and validation.
Your code will need to be updated to use Fields
rather than Args
.
# Old API
from webargs import Arg
args = {
"name": Arg(str, required=True),
"password": Arg(str, validate=lambda p: len(p) >= 6),
"display_per_page": Arg(int, default=10),
"nickname": Arg(multiple=True),
"Content-Type": Arg(dest="content_type", location="headers"),
"location": Arg({"city": Arg(str), "state": Arg(str)}),
"meta": Arg(dict),
}
# New API
from webargs import fields
args = {
"name": fields.Str(required=True),
"password": fields.Str(validate=lambda p: len(p) >= 6),
"display_per_page": fields.Int(missing=10),
"nickname": fields.List(fields.Str()),
"content_type": fields.Str(load_from="Content-Type"),
"location": fields.Nested({"city": fields.Str(), "state": fields.Str()}),
"meta": fields.Dict(),
}
Features:
Changes:
Args
with marshmallow fields (#61).use_kwargs
, missing arguments will have the special value missing
rather than None
.TornadoParser
raises a custom HTTPError
with a messages
attribute when validation fails.Bug fixes:
Nested
field. Thanks @ewang and @chavz for reporting.Support:
examples/schema_example.py
.Changes:
None
, the type conversion function is not called #54. Thanks @marcellarius.Bug fixes:
Features:
matchdict
to PyramidParser
. Thanks @hartror.Bug fixes:
PyramidParser's
use_kwargs
method (#42). Thanks @hartror for the catch and patch.use_args
(#44). Thanks @jacebrowning for the catch and patch.default
and dest
argument on nested Args
(#40 and #46). Thanks @stas.Changes:
ValidationError
is raised by a parser (#38).Features:
webargs.webapp2parser
module. Thanks @Trii.RequiredArgMissingError
. Thanks @stas.Removals:
source
parameter from Arg
.Features:
Changes:
dest
parameter to Arg
constructor which determines the key to be added to the parsed arguments dictionary (#32).targets
parameter to locations
in Parser
constructor, Parser#parse_arg
, Parser#parse
, Parser#use_args
, and Parser#use_kwargs
.Parser#target_handler
to Parser#location_handler
.Deprecation:
source
parameter is deprecated in favor of the dest
parameter.Bug fixes:
validate
parameter of DjangoParser#use_args
.Arg
, filter out extra arguments that are not part of the Arg's
nested dict
(#28). Thanks Derrick Gilland for the suggestion.Args
with both type coercion and multiple=True
(#30). Thanks Steven Manuatu for reporting.RequiredArgMissingError
when a required argument is missing on a request.multiple=True
when nesting Args (#29). Thanks Derrick Gilland for reporting.Arg
type conversion/validation fails. Thanks Andriy Yurchuk.use
argument to be a list of functions.Args
to be nested within each other, e.g. for nested dict validation. Thanks @saritasa for the suggestion.ValidationErrors
to its error handler function, rather than catching all generic Exceptions.Parser.TARGET_MAP
to Parser.__target_map__
.Parser
class that can be used to store processed request data for reuse.TornadoParser
that raised an error when request body is not a string (e.g when it is a Future
). Thanks Josh Carp.Parser.use_kwargs
behavior when an Arg
is allowed missing. The allow_missing
attribute is ignored when use_kwargs
is called.default
may be a callable.ValidationError
to specify a HTTP status code for the error response.'query'
as a valid target name.Arg
or Parser.parse
.__repr__
for Arg
.source
parameter to Arg
constructor. Allows renaming of keys in the parsed arguments dictionary. Thanks Josh Carp.FlaskParser's
handle_error
method attaches the string representation of validation errors on err.data['message']
. The raised exception is stored on err.data['exc']
.Arg
are stored as metadata.TornadoParser's
handle_error
method. Thanks Josh Carp.error
parameter to Parser
constructor that allows a custom error message to be used if schema-level validation fails.UnicodeEncodeError
on Python 2 when an Arg’s validator function received non-ASCII input.Arg
with both default
and target
set (see issue #11).validate
parameter to Parser.parse
and Parser.use_args
. Allows validation of the full parsed output.allow_missing
is True
on an Arg
for which None
is explicitly passed, the value will still be present in the parsed arguments dictionary.Parser's
parse_*
methods return webargs.core.Missing
if the value cannot be found on the request. NOTE: webargs.core.Missing
will not show up in the final output of Parser.parse
.TornadoParser
.Arg's
allow_missing
parameter when multiple=True
.application/json
. Thanks Samir Uppaluru for reporting.use
parameter to Arg
is called before type conversion occurs. Thanks Eric Wang for the suggestion.Parser.target_handler
decorator.Parser.error_handler
decorator.Args
can define their request target by passing in a target
argument.DEFAULT_TARGETS
is now a class member of Parser
. This allows subclasses to override it.use_args
to fail on class-based views in Flask.allow_missing
parameter to Arg
.use_kwargs
decorator. Thanks @venuatu.parse_*
methods take arg
as their fourth argument.error_handler
param to Parser
.targets
param to Parser
. Allows setting default targets.files
target.