CHANGELOG.rst
Features:
pre_load and post_load parameters to marshmallow.fields.Field for
field-level pre- and post-processing (:issue:2787).marshmallow.validate (:pr:2940).Bug fixes:
marshmallow.validate.URL and marshmallow.validate.Email accept Internationalized Domain Names (IDNs) (:issue:2821, :issue:2936).
marshmallow.validate.Email also correctly rejects IDN domains with leading/trailing hyphens.
Thanks :user:touhidurrr for the report.nested in marshmallow.fields.Nested (:pr:2935).Bug fixes:
marshmallow.fields.Number and marshmallow.fields.Mapping abstract base classes to
prevent using them within Schemas (:issue:2924). Thanks :user:MartingaleCoda for reporting.required to be set on marshmallow.fields.Contant (:issue:2900).
Thanks :user:nosnickid for the report and :user:worksbyfriday for the PR.marshmallow.validate.OneOf emitting extra pairs when labels outnumber choices (:issue:2869).
Thanks: user:T90REAL for the report and :user:rstar327 for the PR.partial for a key with data_key set (:pr:2903).
Thanks :user:bysiber for the PR.2902).
Thanks :user:bysiber for the PR.marshmallow.fields.DateTime with format="timestamp_ms" properly
rejects bool values (:pr:2904). Thanks :user:bysiber for the PR.error_messages argument to marshmallow.fields.Field (:pr:1636).
Thanks :user:repole for reporting and :user:dhruvildarji for the PR.Other changes:
ipaddress.* to marshmallow.Schema.TYPE_MAPPING (:issue:1695).
Thanks :user:liberforce for the suggestion and :user:dhruvildarji for the PR.Bug fixes:
fields.Contant(None) (:issue:2868).
Thanks :user:T90REAL for reporting and emmanuel-ferdman for the fix.Bug fixes:
FILE (:issue:2891).
Thanks :user:thanhlecongg for reporting and fixing.Other changes:
many argument of Nested properly overrides schema instance
value (:pr:2854). Thanks :user:jafournier for the PR.Bug fixes:
2025-68480: Merge error store messages without rebuilding collections.
Thanks 카푸치노 for reporting and :user:deckar01 for the fix.Bug fixes:
URL validator is case-insensitive when using custom schemes (:pr:2874).
Thanks :user:T90REAL for the PR.Other changes:
__len__ implementation to missing so that it can be used with
validate.Length <marshmallow.validate.Length> (:pr:2861).
Thanks :user:agentgodzilla for the PR.2363).2864).Bug fixes:
from marshmallow import * (:pr:2823).
Thanks :user:Florian-Laport for the PR.See :ref:upgrading_4_0 for a guide on updating your code.
Features:
Field <marshmallow.fields.Field> constructor kwargs (:issue:2285).
Thanks :user:navignaw for the suggestion.DateTime <marshmallow.fields.DateTime>, Date <marshmallow.fields.Date>, Time <marshmallow.fields.Time>,
TimeDelta <marshmallow.fields.TimeDelta>, and Enum <marshmallow.fields.Enum>
accept their internal value types as valid input (:issue:1415).
Thanks :user:bitdancer for the suggestion.@validates <marshmallow.validates> accepts multiple field names (:issue:1960).
Backwards-incompatible: Decorated methods now receive data_key as a keyword argument.
Thanks :user:dpriskorn for the suggestion and :user:dharani7998 for the PR.Other changes:
Typing: Field <marshmallow.fields.Field> is now a generic type with a type argument for the internal value type.
marshmallow.fields.UUID no longer subclasses marshmallow.fields.String.
marshmallow.Schema.load no longer silently fails to call schema validators when a generator is passed (:issue:1898).
The typing of data is also updated to be more accurate.
Thanks :user:ziplokk1 for reporting.
Backwards-incompatible: Use datetime.date.fromisoformat, datetime.time.fromisoformat, and datetime.datetime.fromisoformat from the standard library to deserialize dates, times and datetimes (:pr:2078).
As a consequence of this change:
from_iso_date, from_iso_time and from_iso_datetime are removed from marshmallow.utils.Remove isoformat, to_iso_time and to_iso_datetime from marshmallow.utils (:pr:2766).
Remove from_rfc, and rfcformat from marshmallow.utils (:pr:2767).
Remove is_keyed_tuple from marshmallow.utils (:pr:2768).
Remove get_fixed_timezone from marshmallow.utils (:pr:2773).
Backwards-incompatible: marshmallow.fields.Boolean no longer serializes non-boolean values (:pr:2725).
Backwards-incompatible: Rename schema parameter to parent in marshmallow.fields.Field._bind_to_schema (:issue:1360).
Backwards-incompatible: Rename pass_many parameter to pass_collection in pre/post processing methods (:issue:1369).
Backwards-incompatible: marshmallow.fields.TimeDelta no longer truncates float values when
deserializing (:pr:2654). This allows microseconds to be preserved, e.g.
.. code-block:: python
from marshmallow import fields
field = fields.TimeDelta()
# Before
field.deserialize(12.9)
datetime.timedelta(seconds=12)
# datetime.timedelta(seconds=12)
# After
field.deserialize(12.9)
# datetime.timedelta(seconds=12, microseconds=900000)
marshmallow.fields.TimeDelta serialization (:pr:2654).serialization_type parameter from
marshmallow.fields.TimeDelta (:pr:2654).Thanks :user:ddelange for the PR.
Schema <marshmallow.schema.Schema>'s context attribute (deprecated since 3.24.0). Passing a context
should be done using contextvars.ContextVar (:issue:1826).
marshmallow 4 provides an experimental Context <marshmallow.experimental.context.Context>
manager class that can be used to both set and retrieve context... code-block:: python
import typing
from marshmallow import Schema, fields
from marshmallow.experimental.context import Context
class UserContext(typing.TypedDict):
suffix: str
class UserSchema(Schema):
name_suffixed = fields.Function(
lambda obj: obj["name"] + Context[UserContext].get()["suffix"]
)
with Context[UserContext]({"suffix": "bar"}):
UserSchema().dump({"name": "foo"})
# {'name_suffixed': 'foobar'}
marshmallow.pre_load, marshmallow.post_load, marshmallow.validates_schema,
receive unknown as a keyword argument (:pr:1632).
Thanks :user:jforand for the PR.decorators <marshmallow.decorators> are keyword-only arguments.json_data parameter of marshmallow.Schema.loads to s
for compatibility with most render module implementations (json, simplejson, etc.) (:pr:2764).
Also make it a positional-only argument.2772).unknown will cause an error in type checkers (:pr:2771).Deprecations/Removals:
fields or additional class Meta options with undeclared fields (:issue:1356).ordered class Meta option is removed (:issue:2146). Field order is already preserved by default.
Set Schema.dict_class to OrderedDict to maintain the previous behavior.marshmallow.base module is removed (:pr:2722).Previously-deprecated APIs have been removed, including:
ordered class Meta <marshmallow.Schema.Meta> option is removed (:issue:2146) (deprecated in 3.26.0).marshmallow.fields.Number is no longer usable as a field in a schema (deprecated in 3.24.0).
Use marshmallow.fields.Integer, marshmallow.fields.Float, or marshmallow.fields.Decimal instead.marshmallow.fields.Mapping is no longer usable as a field in a schema (deprecated in 3.24.0).ValidationError <marshmallow.exceptions.ValidationError> for invalid values (deprecated in 3.24.0).
Returning False is no longer supported (:issue:1775).
Use marshmallow.fields.Dict instead.__version__, __parsed_version__, and __version_info__ attributes (deprecated in 3.21.0).default and missing parameters, which were replaced by dump_default and load_default in 3.13.0 (:pr:1742, :pr:2700).metadata=...
argument instead (:issue:1350).marshmallow.utils.pprint (deprecated in 3.7.0). Use pprint.pprint instead."self" to fields.Nested (deprecated in 3.3.0). Use a callable instead.Field.fail, which was replaced by Field.make_error in 3.0.0.json_module class Meta option (deprecated in 3.0.0b3). Use render_module instead.Bug fixes:
2025-68480: Merge error store messages without rebuilding collections.
Thanks 카푸치노 for reporting and :user:deckar01 for the fix.Bug fixes:
class Meta <marshmallow.Schema.Meta> options (:issue:2804).
Thanks :user:lawrence-law for reporting.Other changes:
data param of Nested._deserialize <marshmallow.fields.Nested._deserialize> (:issue:2802).
Thanks :user:gbenson for reporting.Features:
class Meta <marshmallow.Schema.Meta> options (:pr:2760).marshmallow.Schema.SchemaMeta (:pr:2761).marshmallow.Schema.loads parameter allows bytes and bytesarray (:pr:2769).Bug fixes:
data_key when schema validators raise a ValidationError <marshmallow.exceptions.ValidationError>
with a field_name argument (:issue:2170). Thanks :user:matejsp for reporting.@post_load <marshmallow.post_load> methods where one method appends to
the data and another passes pass_original=True (:issue:1755).
Thanks :user:ghostwheel42 for reporting.URL fields now properly validate file paths (:issue:2249).
Thanks :user:0xDEC0DE for reporting and fixing.Documentation:
upgrading guides <upgrading> for 3.24 and 3.26 (:pr:2780).2757, :pr:2759, :pr:2765, :pr:2774, :pr:2778, :pr:2783, :pr:2796).Deprecations:
ordered class Meta <marshmallow.Schema.Meta> option is deprecated (:issue:2146, :pr:2762).
Field order is already preserved by default. Set marshmallow.Schema.dict_class to collections.OrderedDict
to maintain the previous behavior.Bug fixes:
Tuple <marshmallow.fields.Tuple>,
Boolean <marshmallow.fields.Boolean>, and Pluck <marshmallow.fields.Pluck>
constructors (:pr:2756).marshmallow.class_registry.get_class (:pr:2756).Documentation:
2746, :pr:2747, :pr:2748, :pr:2749, :pr:2750, :pr:2751).Features:
SchemaMeta.get_declared_fields (:pr:2742).Bug fixes:
Schema.opts to allow subclasses to define their own
options classes (:pr:2744).Other changes:
marshmallow.base.SchemaABC for backwards-compatibility (:issue:2743).
Note that this class is deprecated and will be removed in marshmallow 4.
Use marshmallow.schema.Schema as a base class for type-checking instead.Changes:
__new__ to avoid breaking usages of inspect.signature with
Field <marshmallow.fields.Field> classes.
This allows marshmallow-sqlalchemy users to upgrade marshmallow without
upgrading to marshmallow-sqlalchemy>=1.1.1.Documentation:
2739).
Thanks :user:llucax for reporting.Bug fixes:
class_registry.get_class <marshmallow.class_registry.get_class> (:pr:2735).Features:
marshmallow.fields (:pr:2723).2718).Bug fixes:
nested parameter of Nested <marshmallow.fields.Nested> (:pr:2721).Deprecations:
ValidationError <marshmallow.exceptions.ValidationError> for invalid values.
Returning `False`` is no longer supported .context parameter of Schema <marshmallow.schema.Schema> (:issue:1826).
Use contextVars.ContextVar to pass context data instead.Field <marshmallow.fields.Field>, Mapping <marshmallow.fields.Mapping>,
and Number <marshmallow.fields.Number> should no longer be used as fields within schemas.
Use their subclasses instead.Bug fixes:
Schema.from_dict <marshmallow.schema.Schema.from_dict> (:issue:1653).
Thanks :user:SteadBytes for reporting.Support:
marshmallow.fields API reference (:issue:2307).
Thanks :user:AbdealiLoKo for reporting.Bug fixes:
Field, Nested, and Function fields
to resolve PyCharm warnings (:issue:2268).
Thanks :user:Fares-Abubaker for reporting and fixing.Support:
absolute parameter of URL field (:pr:2327).2323).Features:
Schema and Field.Other changes:
2319).2318).Features:
many Meta option to Schema so it expects a collection by default (:issue:2270).
Thanks :user:himalczyk for reporting and :user:deckar01 for the PR.2279).
Thanks :user:deckar01 for the PR.Bug fixes:
2277).
Thanks :user:mrcljx for the PR.Bug fixes:
fields.DateTime (:issue:2133).
Thanks :user:flydzen for reporting.Bug fixes:
2245).
Thanks :user:travnick for reporting.Bug fixes:
URL fields to allow missing user field,
per NWG RFC 3986 (:issue:2232). Thanks :user:ddennerline3 for reporting
and :user:deckar01 for the PR.Other changes:
__version__, __parsed_version__, and __version_info__
attributes are deprecated (:issue:2227). Use feature detection or
importlib.metadata.version("marshmallow") instead.Bug fixes:
Nested field type hint for lambda Schema types (:pr:2164).
Thanks :user:somethingnew2-0 for the PR.Other changes:
2188).
Thanks :user:hugovk for the PR.Bug fixes:
get_declared_fields: pass dict_cls again (:issue:2152).
Thanks :user:Cheaterman for reporting.Features:
absolute parameter to URL validator and Url field (:pr:2123).
Thanks :user:sirosen for the PR.FieldABC and SchemaABC
(:issue:1449). Thanks :user:aditkumar72 for the PR.OrderedSet as default set_class. Schemas are now ordered by default.
(:issue:1744)Bug fixes:
OSError and OverflowError in utils.from_timestamp (:pr:2102).
Thanks :user:TheBigRoomXXL for the PR.2149).
Thanks :user:matejsp for reporting.Other changes:
2067).2135).Features:
timestamp and timestamp_ms formats to fields.DateTime
(:issue:612).
Thanks :user:vgavro for the suggestion and thanks :user:vanHoi for
the PR.Features:
Enum field (:pr:2017) and (:pr:2044).Bug fixes:
Field._serialize signature (:pr:2046).Bug fixes:
fields.Email.__init__ (:pr:2018).
Thanks :user:kkirsche for the PR.2036).Features:
TimeDelta field (:pr:1998).
Thanks :user:marcosatti for the PR.messages_dict property to ValidationError to facilitate type checking
(:pr:1976).
Thanks :user:sirosen for the PR.Features:
ValueError if an invalid value is passed to the unknown
argument (:issue:1721, :issue:1732).
Thanks :user:sirosen for the PR.Other changes:
packaging requirement (:issue:1957).
Thanks :user:MatthewNicolTR for reporting and thanks :user:sirosen for the PR.stacklevel (:pr:1986).
Thanks :user:tirkarthi for the PR.Features:
dict to fields.Nested (:pr:1935).
Thanks :user:sirosen for the PR.Other changes:
1903).
Thanks :user:kkirsche for the PR.1921).1923).1932).
Thanks :user:Isira-Seneviratne for the PR.Bug fixes:
PEP-561 <https://www.python.org/dev/peps/pep-0561/>_
(:pr:1905). Thanks :user:bwindsor for the catch and patch.Bug fixes:
fields.TimeDelta serialization precision (:issue:1865).
Thanks :user:yarsanich for reporting.Other changes:
data arg in Schema.validate to accept
list of dictionaries (:issue:1790, :pr:1868).
Thanks :user:yourun-proger for PR.1882).
Thanks :user:traherom for the PR.1860) Thanks :user:YKdvd for reporting.1862).1863).1888).Features:
missing/default field parameters with
load_default/dump_default (:pr:1742).
Thanks :user:sirosen for the PR.Deprecations:
missing/default field parameters is deprecated and will be
removed in marshmallow 4. load_default/dump_default should be used
instead.Bug fixes:
Field\s as Schema attributes. This reverts a change
introduced in 3.12.0 that causes issues when field names conflict with
Schema attributes or methods. Fields\s are still accessible on a
Schema instance through the fields attribute. (:pr:1843)Bug fixes:
AttributeError when instantiating a
Schema with a field named parent (:issue:1808).
Thanks :user:flying-sheep for reporting and helping with the fix.Features:
validate.And (:issue:1768).
Thanks :user:rugleb for the suggestion.marshmallow.decorators (:issue:1788, :pr:1789).
Thanks :user:michaeldimchuk for the PR.Field\s be accessed by name as Schema attributes (:pr:1631).Other changes:
marshmallow.validate (:pr:1786).marshmallow.validate.Validator an abstract base class (:pr:1786).1785).Bug fixes:
unknown=INCLUDE (:issue:1506).
Thanks :user:rbu for reporting and thanks :user:sirosen for the fix (:pr:1745).Features:
fields.IPInterface, fields.IPv4Interface, and
IPv6Interface (:issue:1733). Thanks :user:madeinoz67
for the suggestion and the PR.AttributeError for missing methods when using fields.Method (:pr:1675).
Thanks :user:lassandroan.Other changes:
hasattr and getattr checks in Field (:pr:1770).Deprecations:
1350). Use the explicit metadata=...
argument instead. Thanks :user:sirosen.Bug fixes:
Mapping.serialize and Mapping.deserialize
(:pr:1685).Dict pass invalid dict on deserialization when no key or
value Field is specified (:pr:1685).Features:
format argument to fields.Time and timeformat class Meta option (:issue:686).
Thanks :user:BennyAlex for the suggestion and thanks :user:infinityxxx for the PR.Other changes:
typing.Optional (:issue:1663).
Thanks :user:nadega for the PR.Features:
fields.IP, fields.IPv4 and fields.IPv6 (:pr:1485). Thanks
:user:mgetka for the PR.Bug fixes:
AwareDateTime (:pr:1658). Thanks :user:adithyabsk for
reporting.Bug fixes:
fields.Boolean correctly serializes non-hashable types (:pr:1633).
Thanks :user:jun0jang for the PR.Deprecations:
marshmallow.pprint is deprecated and will be removed in marshmallow 4 (:issue:1588).Support:
default_error_messages on field classes (:pr:1619). Thanks :user:weeix.Bug fixes:
only and exclude to Nested with an ordered Schema (:pr:1627).
Thanks :user:juannorris for the PR.No code changes--only docs and contributor-facing updates in this release.
Support:
1538).
Thanks :user:pablospizzamiglio for reporting the problem with the
old example and thanks :user:Resinderate for the PR.1587). Thanks :user:EpicWink for the PR.Features:
validate.ContainsNoneOf (:issue:1528).
Thanks :user:Resinderate for the suggestion and the PR.Bug fixes:
class_registry (:pr:1574). Thanks :user:mahenzon.Bug fixes:
Bug fixes:
List(Nested(Field, allow_none=True)
(:issue:1497). Because this fix reverts an optimization introduced to
speed-up serialization and deserialization of lists of nested fields, a
negative impact on performance in this specific case is expected.Features:
1479). Thanks :user:Reskov.Bug fixes:
data param of Schema.load and ValidationError (:issue:1492).
Thanks :user:mehdigmira for reporting and thanks :user:dfirst for the PR.Other changes:
1500). Thanks :user:hukkinj1._serialize override in UUID field (:pr:1489).Features:
fields.Nested may take a callable that returns a schema instance.
Use this to resolve order-of-declaration issues when schemas nest each other (:issue:1146)... code-block:: python
# <3.3
class AlbumSchema(Schema):
title = fields.Str()
artist = fields.Nested("ArtistSchema", only=("name",))
class ArtistSchema(Schema):
name = fields.Str()
albums = fields.List(fields.Nested(AlbumSchema))
# >=3.3
class AlbumSchema(Schema):
title = fields.Str()
artist = fields.Nested(lambda: ArtistSchema(only=("name",)))
class ArtistSchema(Schema):
name = fields.Str()
albums = fields.List(fields.Nested(AlbumSchema))
Deprecations:
"self" to fields.Nested is deprecated.
Use a callable instead... code-block:: python
from marshmallow import Schema, fields
# <3.3
class PersonSchema(Schema):
partner = fields.Nested("self", exclude=("partner",))
friends = fields.List(fields.Nested("self"))
# >=3.3
class PersonSchema(Schema):
partner = fields.Nested(lambda: PersonSchema(exclude=("partner")))
friends = fields.List(fields.Nested(lambda: PersonSchema()))
Other changes:
Number._format_num (:pr:1466). Thanks :user:hukkinj1.1467). Thanks again, :user:hukkinj1.Bug fixes:
load_only and dump_only are both True (:pr:1448).marshmallow.validate (:pr:1446).Support:
1431).Bug fixes:
Schema.dump[s] (:pr:1416).Features:
marshmallow.schema and marshmallow.validate (:pr:1407, :issue:663).Bug fixes:
1409). Thanks :user:lukaszdudek-silvair for reporting.Refactoring:
BaseSchema superclass (:pr:1406).Bug fixes:
Number fields (:pr:1403).
fields.Integer and fields.Decimal inherit from fields.Number.1404).
Thanks :user:metheoryt for reporting.Features:
663).
Type information is distributed per PEP 561 <https://www.python.org/dev/peps/pep-0561/>_ .
Thanks :user:fuhrysteve for helping with this.Bug fixes:
Bug fixes:
only to Nested (:pr:1395).
This bug also affected passing a schema instance to fields.Pluck.Bug fixes:
only and exclude parameters to nested schema instances (:issue:1384).1160).Bug fixes:
data_key is an empty string (:issue:1378).
Thanks :user:jtrakk for reporting.Bug fixes:
1376).super() call in SchemaMeta.__init__ (:pr:1362).Bug fixes:
fields.DateTime within fields.List or fields.Tuple (:issue:1357).
This bug was introduced in 3.0.0rc9. Thanks :user:zblz for reporting.Features:
List(Nested(...)) (:issue:779).1328).Schema.from_dict (:issue:1312).Deprecations/Removals:
Field.fail is deprecated. Use Field.make_error instead.fields.UUID, for consistency with other fields (:issue:1132).Support:
1329).Features:
1132).
This significantly improves serialization performance.DateTime does not affect timezone information
on serialization and deserialization (:issue:1234, :pr:1278).NaiveDateTime and AwareDateTime to enforce timezone awareness
(:issue:1234, :pr:1287).List does not wrap single values in a list on
serialization (:pr:1307).Schema.handle_error receives many and partial as keyword arguments (:pr:1321).raise from more uniformly to improve stack traces (:pr:1313).Nested.__schema to Nested._schema to prevent name mangling (:issue:1289).1309).Deprecations/Removals:
LocalDateTime is removed (:issue:1234).marshmallow.utils.utc is removed. Use datetime.timezone.utc instead.Bug fixes:
List(Nested("self")) (#779 (comment) <https://github.com/marshmallow-code/marshmallow/issues/779#issuecomment-396354987>_).Support:
validate.Regexp's usage re.search (:issue:1285). Thanks :user:macdonaldezra.Features:
only and exclude parameters to Nested fields
within List and Dict (:issue:779, :issue:946).email.utils.parsedate_to_datetime instead of conditionally
using dateutil for parsing RFC dates (:pr:1246).1265)validate.Range.raise from error for better stack traces (:pr:1254). Thanks
:user:fuhrysteve.497, :issue:1234).Bug fixes:
__init__ method of fields.Email and
fields.URL (:issue:1268). Thanks :user:dursk for the catch and patch.Other changes:
fields.List.container to fields.List.inner,
fields.Dict.key_container to fields.Dict.key_field, and
fields.Dict.value_container to fields.Dict.value_field.1261).Features:
many is passed as a keyword argument to methods decorated with
pre_load, post_load, pre_dump, post_dump,
and validates_schema. partial is passed as a keyword argument to
methods decorated with pre_load, post_load and validates_schema.
**kwargs should be added to all decorated methods.min_inclusive and max_exclusive parameters to
validate.Range (:issue:1221). Thanks :user:kdop for the PR.Bug fixes:
partial to Nested containers (part of :issue:779).Other changes:
1216).Support:
1120).
Only Python>=3.5 is supported.
Thank you :user:rooterkyberian for the suggestion and the PR.fields.List and
fields.Tuple for accessing nested attributes (:pr:1188).
Use fields.List(fields.Pluck(...)) instead.python_requires to setup.py (:pr:1194).
Thanks :user:hugovk.pyupgrade in pre-commit (:pr:1195). Thanks
again :user:hugovk.Features:
1129). Thanks :user:hdoupe for the PR.OneOf and ContainsOnly
(:issue:885). Thanks :user:mcgfeller for the suggestion
and :user:maxalbert for the PR.Deprecations/Removals:
fields.FormattedString (:issue:1141). Use
fields.Function or fields.Method instead.Bug fixes:
Features:
fields.Tuple (:issue:1103) Thanks :user:zblz for the PR.fields.Mapping, which makes it easier to support other
mapping types (e.g. OrderedDict) (:issue:1092).
Thank :user:sayanarijit for the suggestion and the PR.Features:
852). Thanks :user:Dunstrom for the PR.fields.Boolean parses "yes"/"no" values (:pr:1081).
Thanks :user:r1b.Other changes:
keys and values arguments to fields.Dict.marshmallow.utils: is_indexable_but_not_string,
float_to_decimal, decimal_to_fixed, from_iso (:pr:1088).marshmallow.compat.string_types.Bug fixes:
Features:
register class Meta option to allow bypassing marshmallow's
internal class registry when memory usage is critical (:issue:660).Bug fixes:
1060).
Thanks :user:taion for the fix.ValidationError.valid_data for List and
Dict fields (:issue:766).Other changes:
marshmallow.__version_info__ (:pr:1074).marshmallow.marshalling internal module (:pr:1070).ValueError is raised when the missing parameter is passed
for required fields (:issue:1040).ValidationError in validators
are no longer passed to the final ValidationError raised upon
validation completion (:issue:996).Features:
ValidationError API.
It now expects a single field name, and error structures are merged
in the final ValidationError raised when validation completes.
This allows schema-level validators to raise errors for individual
fields (:issue:441). Thanks :user:maximkulkin for
writing the original merge_errors implementation in :pr:442 and thanks
:user:lafrech for completing the implementation in :pr:1026.Bug fixes:
TypeError when serializing None with Pluck (:pr:1049).
Thanks :user:toffan for the catch and patch.Bug fixes:
Features:
438). Thanks
:user:arbor-dwatson for the PR. Note: Subclasses of fields.Nested
now take an additional partial parameter in the _deserialize
method.Bug fixes:
Schema.TYPE_MAPPING, which was removed in 3.0.0b17 (:issue:1012).Other changes:
_serialize and _deserialize methods of
all fields.Field subclasses must accept **kwargs (:pr:1007).Bug fixes:
Date deserialization when using custom format (:issue:1001). Thanks
:user:Ondkloss for reporting.Deprecations/Removals:
prefix parameter or Schema class is removed (:issue:991). The same
can be achieved using a @post_dump method.Features:
format option to Date field (:pr:869).DateTime's dateformat Meta option
to datetimeformat. dateformat now applies to Date (:pr:869).
Thanks :user:knagra for implementing these changes.899).
Thanks :user:dushr for the report and the work on the PR.ValueError on Schema instantiation in
case of attribute or data_key collision (:pr:992).Bug fixes:
809). Thanks :user:taion for the PR.unknown is not passed to Nested, default to nested Schema
unknown meta option rather than RAISE (:pr:963).
Thanks :user:vgavro for the PR.fields.Pluck (:pr:990).Bug fixes:
root attribute for nested container fields
on inheriting schemas (:issue:956). Thanks :user:bmcbu
for reporting.Bug fixes:
ValidationError instead of TypeError when non-iterable types are
validated with many=True (:issue:851).many=True no longer iterates over str and collections.abc.Mapping objects and instead
raises a ValidationError with {'_schema': ['Invalid input type.']} (:issue:930).[] as ValidationError.valid_data instead of {} when
many=True (:issue:907).Thanks :user:tuukkamustonen for implementing these changes.
Features:
fields.Pluck for serializing a single field from a nested object
(:issue:800). Thanks :user:timc13 for the feedback and :user:deckar01
for the implementation.only to
fields.Nested is no longer supported. Use fields.Pluck instead
(:issue:800).StringNotCollectionError if only or exclude is
passed as a string to fields.Nested (:pr:931).Float takes an allow_nan parameter to
explicitly allow serializing and deserializing special values (nan,
inf and -inf). allow_nan defaults to False.Other changes:
Nested field now defaults to unknown=RAISE
instead of EXCLUDE. This harmonizes behavior with Schema that
already defaults to RAISE (:issue:908). Thanks :user:tuukkamustonen.Bug fixes:
Nested field
are stored under corresponding field name, not _schema key (:pr:862).Other changes:
unknown option now defaults to RAISE
(#524 (comment) <https://github.com/marshmallow-code/marshmallow/issues/524#issuecomment-397165731>_,
:issue:851).dict as
payload, the dict overwrites any existing error list. Before this change,
it would be appended to the list.StringNotCollectionError if only or exclude is
passed as a string (:issue:316). Thanks :user:paulocheque for
reporting.Features:
unknown option (:issue:524,
:issue:747, :issue:127).
It makes it possible to either "include", "exclude", or "raise".
Thanks :user:tuukkamustonen for the suggestion and thanks
:user:ramnes for the PR... warning::
The default for unknown will be changed to RAISE in the
next release.
Other changes:
None does not imply data were mutated (:issue:347). Thanks
:user:tdevelioglu for reporting.only and exclude are bound by
declared and additional fields. A ValueError is raised if invalid
fields are passed (:issue:636). Thanks :user:jan-23 for reporting.
Thanks :user:ikilledthecat and :user:deckar01 for the PRs.855).Deprecations/Removals:
ValidationError.fields is removed (:issue:840). Access field
instances from Schema.fields.Features:
814). Thanks :user:taion.utils.get_value (:pr:811). Thanks again :user:taion.require_tld argument to fields.URL (:issue:749). Thanks
:user:DenerKup for reporting and thanks :user:surik00 for the PR.fields.UUID deserializes bytes strings using UUID(bytes=b'...') (:pr:625).
Thanks :user:JeffBerger for the suggestion and the PR.Bug fixes:
Dict correctly inherit context from their
parent schema (:issue:820). Thanks :user:RosanneZe for reporting
and :user:deckar01 for the PR.Bug fixes:
Features:
missing and default values are
passed in deserialized form (:issue:378). Thanks :user:chadrik for
the suggestion and thanks :user:lafrech for the PR.Bug fixes:
Features:
data_key parameter to fields for
specifying the key in the input and output data dict. This
parameter replaces both load_from and dump_to (:issue:717).
Thanks :user:lafrech.pass_original=True is passed to one
of the decorators and a collection is being (de)serialized, the
original_data argument will be a single object unless
pass_many=True is also passed to the decorator (:issue:315,
:issue:743). Thanks :user:stj for the PR.Nested field's key is missing (:issue:319). This
reverts :pr:235. Thanks :user:chekunkov reporting and thanks
:user:lafrech for the PR.Dict field (:issue:730). Note:
this is backwards-incompatible with previous 3.0.0bX versions.
Thanks :user:shabble for the report and thanks :user:lafrech for the PR.Features:
377).
The strict parameter is removed.Schema().load and Schema().dump return data instead of a
(data, errors) tuple (:issue:598).Schema().load(None) raises a
ValidationError (:issue:511).See :ref:upgrading_3_0 for a guide on updating your code.
Thanks :user:lafrech for implementing these changes.
Special thanks to :user:MichalKononenko, :user:douglas-treadwell, and
:user:maximkulkin for the discussions on these changes.
Other changes:
load_from
is specified (:pr:714). Thanks :user:lafrech.Support:
Code of Conduct <https://marshmallow.readthedocs.io/en/dev/code_of_conduct.html>_.Bug fixes:
ValidationError.valid_data when a nested field contains errors
(:issue:710). This bug was introduced in 3.0.0b3. Thanks
:user:lafrech.Other changes:
Email and URL fields don't validate
on serialization (:issue:608). This makes them more consistent with the other
fields and improves serialization performance. Thanks again :user:lafrech.validate.URL requires square brackets around IPv6 URLs (:issue:707). Thanks :user:harlov.Features:
Dict field's constructor. This mirrors the List
field's ability to validate its items (:issue:483). Thanks :user:deckar01.Other changes:
utils.from_iso is deprecated in favor of
utils.from_iso_datetime (:issue:694). Thanks :user:sklarsa.Features:
fields.TimeDelta (:issue:537). Thanks :user:Fedalto for the
suggestion and the PR.Support:
CHANGELOG.rst's modified date for
reproducible builds (:issue:679). Thanks :user:bmwiedemann.Fedalto.659). Thanks :user:wonderbeyond
for reporting and thanks :user:yoichi for the PR.Features:
valid_data attribute to ValidationError.strict parameter to Integer (:issue:667). Thanks
:user:yoichi.Deprecations/Removals:
json_module option in favor of render_module (:issue:364, :issue:130). Thanks :user:justanr for the suggestion.Bug fixes:
Number fields don't accept booleans as valid input (:issue:623). Thanks :user:tuukkamustonen for the suggestion and thanks :user:rowillia for the PR.Support:
rowillia.Features:
truthy and falsy params to fields.Boolean (:issue:580). Thanks :user:zwack for the PR. Note: This is potentially a breaking change if your code passes the default parameter positionally. Pass default as a keyword argument instead, e.g. fields.Boolean(default=True).Other changes:
validate.ContainsOnly allows empty and duplicate values (:issue:516, :issue:603). Thanks :user:maximkulkin for the suggestion and thanks :user:lafrech for the PR.Bug fixes:
Features:
fields.Nested respects only='field' when deserializing (:issue:307). Thanks :user:erlingbo for the suggestion and the PR.fields.Boolean parses "on"/"off" (:issue:580). Thanks :user:marcellarius for the suggestion.Other changes:
skip_on_field_errors defaults to True for validates_schema (:issue:352).Features:
dump_only and load_only for Function and Method are set based on serialize and deserialize arguments (:issue:328).Other changes:
fields.Method and fields.Function no longer swallow AttributeErrors (:issue:395). Thanks :user:bereal for the suggestion.validators.Length is no longer a subclass of validators.Range (:issue:458). Thanks :user:deckar01 for the catch and patch.utils.get_func_args no longer returns bound arguments. This is consistent with the behavior of inspect.signature. This change prevents a DeprecationWarning on Python 3.5 (:issue:415, :issue:479). Thanks :user:deckar01 for the PR.utils.get_value and Schema.get_attribute for consistency with Python builtins (e.g. getattr) (:issue:341). Thanks :user:stas for reporting and thanks :user:deckar01 for the PR.430, reverts :issue:242). Thanks :user:mirko for the suggestion.Deprecation/Removals:
__error_handler__, __accessor__, @Schema.error_handler, and @Schema.accessor. Override Schema.handle_error and Schema.get_attribute instead.func parameter of fields.Function. Remove method_name parameter of fields.Method (issue:325). Use the serialize parameter instead.extra parameter from Schema. Use a @post_dump method to add additional data.Bug fixes:
URL and Email fields
(:issue:1522). Thanks :user:nbanmp for the PR.Other changes:
1525).Bug fixes:
validate argument of fields.Email and fields.URL (:issue:1400).Bug fixes:
many value on Schema instances passed to Nested (:issue:1160).
Thanks :user:Kamforka for reporting.Bug fixes:
TypeError exceptions raised by Field._bind_to_schema or Schema.on_bind_field (:pr:1376).Bug fixes:
collections on Python 3.7
(:pr:1354). Thanks :user:nicktimko for the PR.Bug fixes:
TypeError when invalid data type is
passed to a nested schema with @validates (:issue:1342).Bug fixes:
1337).
Thanks :user:airstandley for the catch and patch.1303).
This is a backport of the fix in :pr:857. Thanks :user:cristi23 for the
thorough bug report and the PR.Deprecation/Removals:
1274).Bug fixes:
1251). Thanks :user:diego-plan9 for reporting.Bug fixes:
1147).Bug fixes:
Meta.exclude would not work on
multiple instantiations (:issue:1212). Thanks :user:MHannila for
reporting.Bug fixes:
OverflowError when (de)serializing large integers with
fields.Float (:pr:1177). Thanks :user:brycedrennan for the PR.Bug fixes:
Nested(many=True) would skip first element when
serializing a generator (:issue:1163). Thanks :user:khvn26 for the
catch and patch.Deprecation/Removal:
RemovedInMarshmallow3 warning is raised when using
fields.FormattedString. Use fields.Method or fields.Function
instead (:issue:1141).Bug fixes:
ChangedInMarshmallow3Warning is no longer raised when
strict=False (:issue:1108). Thanks :user:Aegdesil for
reporting.Features:
marshmallow.utils that are removed in
marshmallow 3.Bug fixes:
missing with copy.copy or copy.deepcopy will not
duplicate it (:pr:1099).Features:
marshmallow.__version_info__ (:pr:1074).1075).Bug fixes:
type()
(:issue:732). Thanks :user:asmodehn for writing the tests to
reproduce this issue.Bug fixes:
collections on Python 3.7
(:issue:1027). Thanks :user:nkonin for reporting and
:user:jmargeta for the PR.Bug fixes:
998). Thanks :user:lalvarezguillen for reporting.Bug fixes:
fields.Url (:pr:982). Thanks user:alefnula for the PR.Other changes:
987).Bug fixes:
TypeError when a non-collection is passed to a Schema with many=True.
Instead, raise ValidationError with {'_schema': ['Invalid input type.']} (:issue:906).root attribute for nested container fields on list
on inheriting schemas (:issue:956). Thanks :user:bmcbu
for reporting.These fixes were backported from 3.0.0b15 and 3.0.0b16.
Bug fixes:
948).
Thanks :user:vke-code for the catch and :user:YuriHeupa for the patch.Bug fixes:
load_from when reporting errors for @validates('field_name')
(:issue:748). Thanks :user:m-novikov for the catch and patch.Bug fixes:
only as a string to nested when the passed field
defines dump_to (:issue:800, :issue:822). Thanks
:user:deckar01 for the catch and patch.Bug fixes:
Schema instance (:issue:783). Thanks :user:yupeng0921 and
:user:lafrech for the fix.fields.List(fields.Integer(as_string=True)) (:issue:788). Thanks
:user:cactus for reporting and :user:lafrech for the fix.exclude parameter when passed from parent to
nested schemas (:issue:728). Thanks :user:timc13 for reporting and
:user:deckar01 for the fix.Bug fixes:
2018-17175: Fix behavior when an empty list is passed as the only argument
(:issue:772). Thanks :user:deckar01 for reporting and thanks
:user:lafrech for the fix.Bug fixes:
UnicodeDecodeError when deserializing bytes with a
String field (:issue:650). Thanks :user:dan-blanchard for the
suggestion and thanks :user:4lissonsilveira for the PR.Features:
require_tld parameter to validate.URL (:issue:664).
Thanks :user:sduthil for the suggestion and the PR.Bug fixes:
__getitem__
(:issue:669). Thanks :user:MichalKononenko.Bug fixes:
556). Thanks :user:lafrech for reporting.Bug fixes:
attribute parameter of fields (:issue:450). Thanks :user:itajaja for reporting.Bug fixes:
SchemaOpts constructor (:issue:597). Thanks :user:Wesmania for reporting and thanks :user:frol for the fix.Bug fixes:
ordered option when Schema subclasses define class Meta (:issue:593). Thanks :user:frol.Support:
Bug fixes:
ordered=True (:issue:592). Thanks :user:frol.Features:
577). Thanks :user:rowillia for the PR.Bug fixes:
None rather returning the field itself. This fixes a corner case introduced in :issue:572. Thanks :user:touilleMan for reporting and :user:YuriHeupa for the fix.Bug fixes:
Nested field is composed within a List field (:issue:572). Thanks :user:avish for reporting and :user:YuriHeupa for the PR.Features:
'child.field') to the dump_only and load_only parameters of Schema (:issue:572). Thanks :user:YuriHeupa for the PR.schemes parameter to fields.URL (:issue:574). Thanks :user:mosquito for the PR.Bug fixes:
strict class Meta option to be overridden by constructor (:issue:550). Thanks :user:douglas-treadwell for reporting and thanks :user:podhmo for the PR.Features:
marshmallow.fields in marshmallow/__init__.py to save an import when importing the marshmallow module (:issue:557). Thanks :user:mindojo-victor.Support:
558). Thanks :user:altaurog.Bug fixes:
ValidationError on each Schema.load call (:issue:565). Thanks :user:jbasko for the catch and patch.Support:
test_utils.test_get_value() (:issue:562). Thanks :user:nelfin.Bug fixes:
Function field works with callables that use Python 3 type annotations (:issue:540). Thanks :user:martinstein for reporting and thanks :user:sabinem, :user:lafrech, and :user:maximkulkin for the work on the PR.Bug fixes:
Number fields when as_string=True is passed (:issue:538). Thanks :user:jessemyers for reporting.Bug fixes:
Decimal (:issue:534). Thanks :user:gdub.uuid.UUID objects (:issue:532). Thanks :user:pauljz.Bug fixes:
validate.Equal(False) (:issue:484). Thanks :user:pktangyue for reporting and thanks :user:tuukkamustonen for the fix.strict behavior when errors are raised in pre_dump/post_dump processors (:issue:521). Thanks :user:tvuotila for the catch and patch.528). Thanks again :user:tvuotila.Features:
472). Thanks :user:dbertouille for the suggestion and for the PR.Bug fixes:
datetime.time objects with microseconds (:issue:464). Thanks :user:Tim-Erwin for reporting and thanks :user:vuonghv for the fix.@validates consistent with field validator behavior: if validation fails, the field will not be included in the deserialized output (:issue:391). Thanks :user:martinstein for reporting and thanks :user:vuonghv for the fix.Decimal field coerces input values to a string before deserializing to a decimal.Decimal object in order to avoid transformation of float values under 12 significant digits (:issue:434, :issue:435). Thanks :user:davidthornton for the PR.Features:
only and exclude parameters to take nested fields, using dot-delimited syntax (e.g. only=['blog.author.email']) (:issue:402). Thanks :user:Tim-Erwin and :user:deckar01 for the discussion and implementation.Support:
deckar01.field.parent and field.name accessible to on_bind_field (:issue:449). Thanks :user:immerrr.No code changes in this release. This is a reupload in order to distribute an sdist for the last hotfix release. See :issue:443.
Support:
433). Thanks :user:rrajaravi for reporting.Bug fixes:
type constructor without getting added to the class registry (which is useful for saving memory).Features:
Nested field's on_bind_field method (:issue:408). Thanks :user:immerrr for the PR.ValidationError kwargs (:issue:418). Thanks :user:russelldavies for helping implement this.Other changes:
root, parent, and name from SchemaABC (:issue:410). Thanks :user:Tim-Erwin for the PR.Bug fixes:
load_from when reporting errors for nested required fields (:issue:414). Thanks :user:yumike.Features:
partial argument to Schema.validate (:issue:379). Thanks :user:tdevelioglu for the PR.equal argument to validate.Length. Thanks :user:daniloakamine.List field (:issue:345). Thanks :user:maximkulkin for the report and the PR.Features:
partial argument to Schema.load (:issue:369). Thanks :user:tdevelioglu for the PR.schemes argument to validate.URL (:issue:356).Bug fixes:
360). Thanks :user:alexmorken for the catch and patch.Bug fixes:
343, :issue:353). Thanks :user:jmcarp for the patch. Thanks :user:edgarallang and :user:jmcarp for reporting.Features:
skip_on_field_errors parameter to validates_schema (:issue:323). Thanks :user:jjvattamattom for the suggestion and :user:d-sutherland for the PR.Bug fixes:
FormattedString serialization (:issue:348). Thanks :user:acaird for reporting.@validates behavior when used when attribute is specified and strict=True (:issue:350). Thanks :user:density for reporting.Features:
dump_to parameter to fields (:issue:310). Thanks :user:ShayanArmanPercolate for the suggestion. Thanks :user:franciscod and :user:ewang for the PRs.deserialize function passed to fields.Function can optionally receive a context argument (:issue:324). Thanks :user:DamianHeard.serialize function passed to fields.Function is optional (:issue:325). Thanks again :user:DamianHeard.serialize function passed to fields.Method is optional (:issue:329). Thanks :user:justanr.Deprecation/Removal:
func argument of fields.Function has been renamed to serialize.method_name argument of fields.Method has been renamed to serialize.func and method_name are still present for backwards-compatibility, but they will both be removed in marshmallow 3.0.
Bug fixes:
only (:issue:320). Thanks :user:carlos-alberto for reporting and :user:eprikazc for the PR.Features:
partial argument to Schema and Schema.load (:issue:290). Thanks :user:taion.Deprecation/Removals:
Query and QuerySelect fields are removed.required and allow_none is removed. Pass the error_messages argument instead.Support:
225). Thanks :user:martinstein for the suggestion and :user:juanrossi for the PR.Bug fixes:
iter will modify position, e.g. Pymongo cursors (:issue:303). Thanks :user:Mise for the catch and patch.Bug fixes:
@validates_schema(many=True) (:issue:297). Thanks :user:d-sutherland for reporting.@validates with a nested field when many=True (:issue:298). Thanks :user:nelfin for the catch and patch.Bug fixes:
Constant field deserializes to its value regardless of whether its field name is present in input data (:issue:291). Thanks :user:fayazkhan for reporting.Features:
Dict field for arbitrary mapping data (:issue:251). Thanks :user:dwieeb for adding this and :user:Dowwie for the suggestion.Field.root property, which references the field's Schema.Deprecation/Removals:
extra param of Schema is deprecated. Add extra data in a post_load method instead.UnmarshallingError and MarshallingError are removed.Bug fixes:
287). Thanks :user:evgeny-sureev for the patch.missing=None on a field, allow_none will be set to True.Other changes:
List's inner field will have the list field set as its parent. Use root to access the Schema.Features:
Field.default_error_messages attribute and error_messages parameter, respectively).Deprecation/Removals:
make_object. Use a post_load method instead (:issue:277).error parameter and attribute of Field.required and allow_none is deprecated. Pass the error_messages argument instead. This API will be removed in version 2.2.Arbitrary, Fixed, and Price fields (:issue:86). Use Decimal instead.Select / Enum fields (:issue:135). Use the OneOf validator instead.Bug fixes:
Nested fields when many=True. Thanks :user:alexmorken.pre_dump methods are invoked before implicit field creation. Thanks :user:makmanalp for reporting.Nested field.only argument passed to a Schema is bounded by the fields option (:issue:183). Thanks :user:lustdante for the suggestion.Changes from 2.0.0rc2:
error_handler and accessor options are replaced with the handle_error and get_attribute methods :issue:284.marshmallow.compat.plain_function since it is no longer used.List field (:issue:231). Thanks :user:density for reporting.Bachmann1234 for the fix.Deprecation/Removals:
make_object is deprecated. Use a post_load method instead (:issue:277). This method will be removed in the final 2.0 release.Schema.accessor and Schema.error_handler decorators are deprecated. Define the accessor and error_handler class Meta options instead.Bug fixes:
ValidationError (:issue:273). Thanks :user:evgeny-sureev for the catch and patch.Changes from 2.0.0rc1:
raw parameter of the pre_*, post_*, validates_schema decorators was renamed to pass_many (:issue:276).pass_original parameter to post_load and post_dump (:issue:216).pre_*, post_*, and validates_* decorators must be instance methods. Class methods and instance methods are not supported at this time.Features:
fields.Field._deserialize now takes attr and data as arguments (:issue:172). Thanks :user:alexmic and :user:kevinastone for the suggestion.Field's attribute to be modified during deserialization (:issue:266). Thanks :user:floqqi.Nested fields (:issue:269). Thanks :user:jomag for the suggestion.Schema.on_bind_field hook which allows a Schema to modify its fields when they are bound.231). Thanks :user:touilleMan for the suggestion.Deprecation/Removals:
Schema.validator, Schema.preprocessor, and Schema.data_handler are removed. Use validates_schema, pre_load, and post_dump instead.QuerySelect and QuerySelectList are deprecated (:issue:227). These fields will be removed in version 2.1.utils.get_callable_name is removed.Bug fixes:
DateTime field, it is always used for deserialization (:issue:248). Thanks :user:bartaelterman and :user:praveen-p.Support:
224).201).Features:
alexmorken.load_only and dump_only class Meta options. Thanks :user:kelvinhammond.Nested field is required, recursively validate any required fields in the nested schema (:issue:235). Thanks :user:max-orhai.Nested field for which many=True. Thanks again :user:max-orhai.Bug fixes:
make_object is only called after all validators and postprocessors have finished (:issue:253). Thanks :user:sunsongxp for reporting.Schema and strict=False, store a _schema error in the errors dict rather than raise an exception (:issue:261). Thanks :user:density for reporting.Other changes:
make_object is only called when input data are completely valid (:issue:243). Thanks :user:kissgyorgy for reporting.URL and Email validators so that they don't include user input (:issue:255).Email validator permits email addresses with non-ASCII characters, as per RFC 6530 (:issue:221). Thanks :user:lextoumbourou for reporting and :user:mwstobo for sending the patch.Features:
List field respects the attribute argument of the inner field. Thanks :user:jmcarp.container field List field has access to its parent Schema via its parent attribute. Thanks again :user:jmcarp.Deprecation/Removals:
73). Use the class-based validators in marshmallow.validate instead.Bug fixes:
fields.Nested correctly serializes nested sets (:issue:233). Thanks :user:traut.Changes from 2.0.0b3:
load_from is used on deserialization, the value of load_from is used as the key in the errors dict (:issue:232). Thanks :user:alexmorken.Features:
marshmallow.validates_schema decorator for defining schema-level validators (:issue:116).marshmallow.validates decorator for defining field validators as Schema methods (:issue:116). Thanks :user:philtay.__marshallable__ on complex objects is no longer necessary.fields.Constant. Thanks :user:kevinastone.Deprecation/Removals:
skip_missing class Meta option. By default, missing inputs are excluded from serialized output (:issue:211).context parameter that gets passed to methods for Method fields.Schema.validator is deprecated. Use marshmallow.validates_schema instead.utils.get_func_name is removed. Use utils.get_callable_name instead.Bug fixes:
28). Thanks :user:makmanalp for reporting.Other changes:
utils.get_value for Function and Method fields (:issue:208). Thanks :user:jmcarp.many=True will not result in an error. Be very careful to pass the many argument when necessary.Support:
Changes from 2.0.0b2:
Boolean field serializes None to None, for consistency with other fields (:issue:213). Thanks :user:cmanallen for reporting.load_only fields do not get validated during serialization.@marshmallow.validates_schema(pass_original=True) instead.Features:
__repr__ methods to validators (:issue:204). Thanks :user:philtay.NaN, Infinity, and -Infinity are invalid values for fields.Decimal. Pass allow_nan=True to allow these values. Thanks :user:philtay.Changes from 2.0.0b1:
None for Time, TimeDelta, and Date fields (a regression introduced in 2.0.0a1).Includes bug fixes from 1.2.6.
Features:
153, :issue:202).OPTIONS_CLASS in SchemaMeta. This makes Schema.opts available in metaclass methods. It also causes validation to occur earlier (upon Schema class declaration rather than instantiation).SchemaMeta.get_declared_fields class method to support adding additional declared fields.Deprecation/Removals:
allow_null parameter of fields.Nested (:issue:203).Changes from 2.0.0a1:
None for fields.Email.Features:
many=True, the errors dictionary returned by dump and load will be keyed on the indices of invalid items in the (de)serialized collection (:issue:75). Add index_errors=False on a Schema's class Meta options to disable this behavior.None. The allow_none parameter can override this behavior.Field's default parameter is only used if explicitly set and the field's value is missing in the input to Schema.dump. If not set, the key will not be present in the serialized output for missing values . This is the behavior for all fields. fields.Str no longer defaults to '', fields.Int no longer defaults to 0, etc. (:issue:199). Thanks :user:jmcarp for the feedback.strict mode, a ValidationError is raised. Error messages are accessed via the ValidationError's messages attribute (:issue:128).allow_none parameter to fields.Field. If False (the default), validation fails when the field's value is None (:issue:76, :issue:111). If allow_none is True, None is considered valid and will deserialize to None.118). Thanks :user:ksesong for the suggestion.pre_load, post_load, pre_dump, and post_dump Schema method decorators for defining pre- and post- processing routines (:issue:153, :issue:179). Thanks :user:davidism, :user:taion, and :user:jmcarp for the suggestions and feedback. Thanks :user:taion for the implementation.required validation is configurable. (:issue:78). Thanks :user:svenstaro for the suggestion. Thanks :user:0xDCA for the implementation.load_from parameter to fields (:issue:125). Thanks :user:hakjoon.load_only and dump_only parameters to fields (:issue:61, :issue:87). Thanks :user:philtay.missing parameter to fields (:issue:115). Thanks :user:philtay.raw_data argument which contains raw input data, incl. data not specified in the schema (:issue:127). Thanks :user:ryanlowe0.validate.OneOf (:issue:135) and validate.ContainsOnly (:issue:149) validators. Thanks :user:philtay.{input} and other values (depending on the validator).fields.TimeDelta always serializes to an integer value in order to avoid rounding errors (:issue:105). Thanks :user:philtay.include class Meta option to support field names which are Python keywords (:issue:139). Thanks :user:nickretallack for the suggestion.exclude parameter is respected when used together with only parameter (:issue:165). Thanks :user:lustdante for the catch and patch.fields.List works as expected with generators and sets (:issue:185). Thanks :user:sergey-aganezov-jr.Deprecation/Removals:
MarshallingError and UnmarshallingError error are deprecated in favor of a single ValidationError (:issue:160).context argument passed to Method fields is deprecated. Use self.context instead (:issue:184).ForcedError.74). Plain generators of validators are still supported.Select/Enum field is deprecated in favor of using validate.OneOf validator (:issue:135).Schema.data and Schema.errors properties) (:issue:73).null value.Other changes:
Marshaller, Unmarshaller were moved to marshmallow.marshalling. These should be considered private API (:issue:129).allow_null=True the default for Nested fields. This will make None serialize to None rather than a dictionary with empty values (:issue:132). Thanks :user:nickrellack for the suggestion.Bug fixes:
fields.Decimal.fields.Boolean to be customized with the error parameter (like other fields).Bug fixes:
Nested field when many=True (:issue:188). Thanks :user:juanrossi for reporting.Support:
taion.Bug fixes:
as_string on fields.Integer (:issue:173). Thanks :user:taion for the catch and patch.Other changes:
fields.Field. Thanks :user:taion.Support:
_postprocess method in docs. Thanks again :user:taion.Bug fixes:
ordered class Meta option (:issue:162). Thanks :user:stephenfin for reporting.Bug fixes:
skip_missing and accessor options when many=True (:issue:137). Thanks :user:3rdcycle.AttributeError when nesting schemas with schema-level validators (:issue:144). Thanks :user:vovanbo for reporting.Bug fixes:
Schema's error_handler--if defined--will execute if Schema.validate returns validation errors (:issue:121).None returns None rather than raising an AttributeError (:issue:123). Thanks :user:RealSalmon for the catch and patch.Features:
QuerySelect and QuerySelectList fields (:issue:84).marshmallow.validate into class-based callables to make them easier to use when declaring fields (:issue:85).Decimal field which is safe to use when dealing with precise numbers (:issue:86).Thanks :user:philtay for these contributions.
Bug fixes:
Date fields correctly deserializes to a datetime.date object when python-dateutil is not installed (:issue:79). Thanks :user:malexer for the catch and patch.AttributeError when using a class-based validator.as_string behavior of Number fields when serializing to default value.None or the empty string with either a DateTime, Date, Time or TimeDelta results in the correct unmarshalling errors (:issue:96). Thanks :user:svenstaro for reporting and helping with this.106). Thanks :user:vesauimonen for the catch and patch.Schema.loads correctly defaults to use the value of self.many rather than defaulting to False (:issue:108). Thanks :user:davidism for the catch and patch.88). Thanks :user:amikholap for reporting.dict or list to a ValidationError (:issue:110). Thanks :user:ksesong for reporting.Deprecation:
validate module are deprecated in favor of the class-based validators (:issue:85).Arbitrary, Price, and Fixed fields are deprecated in favor of the Decimal field (:issue:86).Support:
77).Ch00k.99). Thanks :user:svenstaro.Features:
Schema.validate method which validates input data against a schema. Similar to Schema.load, but does not call make_object and only returns the errors dictionary.validate module. Thanks :user:philtay.strict mode.Bug fixes:
dict (e.g. "items"). Thanks :user:rozenm for reporting.many=True, None serializes to an empty list. Thanks :user:nickretallack for reporting.many argument passed to dump and load. Thanks :user:svenstaro for reporting and helping with this.skip_missing behavior for String and List fields. Thanks :user:malexer for reporting.DateTime, TimeDelta, Date, and Time fields.Support:
Hotfix release.
Schema.dump and Schema.load.Adds new features, speed improvements, better error handling, and updated documentation.
skip_missing class Meta option.default may be a callable.Schema.accessor decorator or the __accessor__ class member.URL and Email fields are validated upon serialization.dump and load can receive the many argument.repr for Field classes.fields.missing and its serialized value is None, it will not be included in the final serialized result.OrderedDict by default. If you want ordered field output, you must explicitly set the ordered option to True.error parameter of the Field constructor is deprecated. Raise a ValidationError instead.Major reworking and simplification of the public API, centered around support for deserialization, improved validation, and a less stateful Schema class.
Serializer to Schema.Schema.dump and Schema.load methods for serializing and deserializing, respectively.Serializer.json and Serializer.to_json. Use Schema.dumps instead.Field classes implement _serialize and _deserialize methods. serialize and deserialize comprise the public API for a Field. Field.format and Field.output have been removed.exceptions.ForcedError which allows errors to be raised during serialization (instead of storing errors in the errors dict).DateTime field serializes to ISO8601 format by default (instead of RFC822).Serializer.factory method. It is no longer necessary with the dump method.exclude or only to prevent infinite recursion.load and dump have lists of error messages keyed by field name.validated decorator. Validation occurs within Field methods.Function field raises a ValueError if an uncallable object is passed to its constructor.Nested fields inherit context from their parent.Schema.preprocessor and Schema.validator decorators for registering preprocessing and schema-level validation functions respectively.ValidationError within a validation function.required parameter on Nested fields.namedtuple) with class Meta options.Fixed and Price fields.Schemas can inherit fields from non-Schema base classes (e.g. mixins). Also, fields are inherited according to the MRO (rather than recursing over base classes). Thanks :user:jmcarp.Str, Bool, and Int field class aliases.Serializer.error_handler decorator that registers a custom error handler.Serializer.data_handler decorator that registers data post-processing callbacks.process_data method is deprecated. Use the data_handler decorator instead.extra data together with many=True. Thanks :user:buttsicles for reporting.required=True validation is violated for a given Field, it will raise an error message that is different from the message specified by the error argument. Thanks :user:asteinlein.validated decorator should only wrap a Field class's output method.namedtuple and KeyedTuple.Serializer.data override-able.Serializer.factory for creating a factory function that returns a Serializer instance.MarshallingError stores its underlying exception as an instance variable. This is useful for inspecting errors.fields.Select is aliased to fields.Enum.fields.__all__ and marshmallow.__all__ so that the modules can be more easily extended.Serializer.OPTIONS_CLASS as a class variable so that options defaults can be overridden.Serializer.process_data hook that allows subclasses to manipulate the final output data.json_module class Meta option.required option to fields . Thanks :user:DeaconDesperado.Integer field default. It is now 0 instead of 0.0. Thanks :user:kalasjocke.context param to Serializer. Allows accessing arbitrary objects in Function and Method fields.Function and Method fields raise MarshallingError if their argument is uncallable.validate parameter.utils.from_rfc for parsing RFC datestring to Python datetime object.utils.to_marshallable_type for improved performance.error parameter to a field.fields.NumberField -> fields.Number.fields.Select. Thanks :user:ecarreras."self" into fields.Nested (only up to depth=1).many=True if serializing to a list. This ensures that marshmallow handles singular objects correctly, even if they are iterable.only parameter is a field name, only return a single value for the nested object (instead of a dict) or a flat list of values.__marshallable__ method, if defined, takes precedence over __getitem__.additional class Meta option.dateformat class Meta option.Serializer.to_data method. Just use Serialize.data property.None.isoformat and rfcformat functions moved to utils.py.DateTime field (first parameter is dateformat).to_json returns bytestrings.fields Meta option.None to a serializer.only and exclude parameters to Serializer constructor.strict parameter and option: causes Serializer to raise an error if invalid data are passed in, rather than storing errors.class Meta paradigm allows you to specify fields more concisely. Can specify fields and exclude options.format parameter to DateTime field constructor. Can either be "rfc" (default), "iso", or a date format string.MarshallingException -> MarshallingError.marshmallow.core -> marshmallow.serializer.fields.Method.fields.Function.extra param when initializing a Serializer.relative parameter to fields.Url that allows for relative URLs.