marshmallow 3.23.3__tar.gz → 3.24.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {marshmallow-3.23.3 → marshmallow-3.24.1}/CHANGELOG.rst +32 -2
- {marshmallow-3.23.3 → marshmallow-3.24.1}/CONTRIBUTING.rst +11 -11
- {marshmallow-3.23.3 → marshmallow-3.24.1}/PKG-INFO +1 -1
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/code_of_conduct.rst +12 -12
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/custom_fields.rst +8 -9
- marshmallow-3.24.1/docs/dashing.json +22 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/examples.rst +2 -2
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/extending.rst +13 -20
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/install.rst +2 -2
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.fields.rst +1 -1
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/nesting.rst +6 -6
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/quickstart.rst +18 -19
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/upgrading.rst +14 -16
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/why.rst +18 -18
- {marshmallow-3.23.3 → marshmallow-3.24.1}/pyproject.toml +4 -1
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/base.py +0 -32
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/class_registry.py +10 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/fields.py +123 -70
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/schema.py +26 -17
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/validate.py +17 -9
- marshmallow-3.24.1/src/marshmallow/warnings.py +10 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/base.py +2 -3
- marshmallow-3.24.1/tests/mypy_test_cases/test_class_registry.py +4 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_decorators.py +2 -2
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_deserialization.py +26 -20
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_fields.py +7 -7
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_schema.py +126 -116
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_serialization.py +15 -7
- marshmallow-3.23.3/docs/dashing.json +0 -22
- marshmallow-3.23.3/src/marshmallow/warnings.py +0 -2
- {marshmallow-3.23.3 → marshmallow-3.24.1}/LICENSE +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/NOTICE +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/README.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/SECURITY.md +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/.gitignore +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/_static/marshmallow-logo.png +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/_templates/donate.html +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/_templates/useful-links.html +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/about.rst.inc +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/api_reference.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/authors.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/changelog.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/conf.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/contributing.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/ecosystem.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/index.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/kudos.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/license.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.class_registry.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.decorators.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.error_store.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.exceptions.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.schema.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.utils.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/marshmallow.validate.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/docs/whos_using.rst +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/__init__.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/decorators.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/error_store.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/exceptions.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/orderedset.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/py.typed +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/types.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/src/marshmallow/utils.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/__init__.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/conftest.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/foo_serializer.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/mypy_test_cases/test_validation_error.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_error_store.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_exceptions.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_options.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_registry.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_utils.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_validate.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tests/test_version_attributes.py +0 -0
- {marshmallow-3.23.3 → marshmallow-3.24.1}/tox.ini +0 -0
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
---------
|
|
3
3
|
|
|
4
|
+
3.24.1 (2025-01-06)
|
|
5
|
+
*******************
|
|
6
|
+
|
|
7
|
+
Bug fixes:
|
|
8
|
+
|
|
9
|
+
- Typing: Fix typing for `class_registry.get_class <marshmallow.class_registry.get_class>` (:pr:`2735`).
|
|
10
|
+
|
|
11
|
+
3.24.0 (2025-01-06)
|
|
12
|
+
*******************
|
|
13
|
+
|
|
14
|
+
Features:
|
|
15
|
+
|
|
16
|
+
- Typing: Improve typings in `marshmallow.fields` (:pr:`2723`).
|
|
17
|
+
- Typing: Replace type comments with inline typings (:pr:`2718`).
|
|
18
|
+
|
|
19
|
+
Bug fixes:
|
|
20
|
+
|
|
21
|
+
- Typing: Fix type hint for ``nested`` parameter of `Nested <marshmallow.fields.Nested>`.
|
|
22
|
+
|
|
23
|
+
Deprecations:
|
|
24
|
+
|
|
25
|
+
- Custom validators should raise a `ValidationError <marshmallow.exceptions.ValidationError>` for invalid values.
|
|
26
|
+
Returning `False`` is no longer supported .
|
|
27
|
+
- Deprecate ``context`` parameter of `Schema <marshmallow.schema.Schema>` (:issue:`1826`).
|
|
28
|
+
Use `contextVars.ContextVar` to pass context data instead.
|
|
29
|
+
- `Field <marshmallow.fields.Field>`, `Mapping <marshmallow.fields.Mapping>`,
|
|
30
|
+
and `Number <marshmallow.fields.Number>` should no longer be used as fields within schemas.
|
|
31
|
+
Use their subclasses instead.
|
|
32
|
+
|
|
33
|
+
|
|
4
34
|
3.23.3 (2025-01-03)
|
|
5
35
|
*******************
|
|
6
36
|
|
|
@@ -1053,7 +1083,7 @@ Features:
|
|
|
1053
1083
|
The ``strict`` parameter is removed.
|
|
1054
1084
|
- *Backwards-incompatible*: ``Schema().load`` and ``Schema().dump`` return ``data`` instead of a
|
|
1055
1085
|
``(data, errors)`` tuple (:issue:`598`).
|
|
1056
|
-
- *Backwards-
|
|
1086
|
+
- *Backwards-incompatible*: ``Schema().load(None)`` raises a
|
|
1057
1087
|
``ValidationError`` (:issue:`511`).
|
|
1058
1088
|
|
|
1059
1089
|
See :ref:`upgrading_3_0` for a guide on updating your code.
|
|
@@ -1256,7 +1286,7 @@ Bug fixes:
|
|
|
1256
1286
|
This is a backport of the fix in :pr:`857`. Thanks :user:`cristi23` for the
|
|
1257
1287
|
thorough bug report and the PR.
|
|
1258
1288
|
|
|
1259
|
-
Deprecation/
|
|
1289
|
+
Deprecation/Removals:
|
|
1260
1290
|
|
|
1261
1291
|
- Python 2.6 is no longer officially supported (:issue:`1274`).
|
|
1262
1292
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Contributing
|
|
1
|
+
Contributing guidelines
|
|
2
2
|
=======================
|
|
3
3
|
|
|
4
4
|
So you're interested in contributing to marshmallow or `one of our associated
|
|
@@ -7,21 +7,21 @@ welcome contributions from anyone willing to work in good faith with
|
|
|
7
7
|
other contributors and the community (see also our
|
|
8
8
|
:doc:`code_of_conduct`).
|
|
9
9
|
|
|
10
|
-
Security
|
|
10
|
+
Security contact information
|
|
11
11
|
----------------------------
|
|
12
12
|
|
|
13
13
|
To report a security vulnerability, please use the
|
|
14
14
|
`Tidelift security contact <https://tidelift.com/security>`_.
|
|
15
15
|
Tidelift will coordinate the fix and disclosure.
|
|
16
16
|
|
|
17
|
-
Questions,
|
|
17
|
+
Questions, feature requests, bug reports, and feedback…
|
|
18
18
|
-------------------------------------------------------
|
|
19
19
|
|
|
20
20
|
…should all be reported on the `Github Issue Tracker`_ .
|
|
21
21
|
|
|
22
22
|
.. _`Github Issue Tracker`: https://github.com/marshmallow-code/marshmallow/issues?state=open
|
|
23
23
|
|
|
24
|
-
Ways to
|
|
24
|
+
Ways to contribute
|
|
25
25
|
------------------
|
|
26
26
|
|
|
27
27
|
- Comment on some of marshmallow's `open issues <https://github.com/marshmallow-code/marshmallow/issues>`_ (especially those `labeled "feedback welcome" <https://github.com/marshmallow-code/marshmallow/issues?q=is%3Aopen+is%3Aissue+label%3A%22feedback+welcome%22>`_). Share a solution or workaround. Make a suggestion for how a feature can be made better. Opinions are welcome!
|
|
@@ -34,10 +34,10 @@ Ways to Contribute
|
|
|
34
34
|
- Send a PR for an open issue (especially one `labeled "help wanted" <https://github.com/marshmallow-code/marshmallow/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22>`_). The next section details how to contribute code.
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
Contributing
|
|
37
|
+
Contributing code
|
|
38
38
|
-----------------
|
|
39
39
|
|
|
40
|
-
Setting
|
|
40
|
+
Setting up for local development
|
|
41
41
|
++++++++++++++++++++++++++++++++
|
|
42
42
|
|
|
43
43
|
1. Fork marshmallow_ on Github.
|
|
@@ -63,20 +63,20 @@ Setting Up for Local Development
|
|
|
63
63
|
# The pre-commit CLI was installed above
|
|
64
64
|
$ pre-commit install --allow-missing-config
|
|
65
65
|
|
|
66
|
-
Git
|
|
66
|
+
Git branch structure
|
|
67
67
|
++++++++++++++++++++
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
marshmallow abides by the following branching model:
|
|
70
70
|
|
|
71
71
|
``dev``
|
|
72
72
|
Current development branch. **New features should branch off here**.
|
|
73
73
|
|
|
74
74
|
``X.Y-line``
|
|
75
|
-
Maintenance branch for release ``X.Y``. **Bug fixes should be sent to the most recent release branch.**
|
|
75
|
+
Maintenance branch for release ``X.Y``. **Bug fixes should be sent to the most recent release branch.** A maintainer will forward-port the fix to ``dev``. Note: exceptions may be made for bug fixes that introduce large code changes.
|
|
76
76
|
|
|
77
77
|
**Always make a new branch for your work**, no matter how small. Also, **do not put unrelated changes in the same branch or pull request**. This makes it more difficult to merge your changes.
|
|
78
78
|
|
|
79
|
-
Pull
|
|
79
|
+
Pull requests
|
|
80
80
|
++++++++++++++
|
|
81
81
|
|
|
82
82
|
1. Create a new local branch.
|
|
@@ -134,7 +134,7 @@ Changes in the `docs/` directory will automatically trigger a rebuild.
|
|
|
134
134
|
|
|
135
135
|
.. _contributing_examples:
|
|
136
136
|
|
|
137
|
-
Contributing
|
|
137
|
+
Contributing examples
|
|
138
138
|
+++++++++++++++++++++
|
|
139
139
|
|
|
140
140
|
Have a usage example you'd like to share? A custom `Field` that others might find useful? Feel free to add it to the `examples <https://github.com/marshmallow-code/marshmallow/tree/dev/examples>`_ directory and send a pull request.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: marshmallow
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.24.1
|
|
4
4
|
Summary: A lightweight library for converting complex datatypes to and from native Python datatypes.
|
|
5
5
|
Author-email: Steven Loria <sloria1@gmail.com>
|
|
6
6
|
Maintainer-email: Steven Loria <sloria1@gmail.com>, Jérôme Lafréchoux <jerome@jolimont.fr>, Jared Deckard <jared@shademaps.com>
|
|
@@ -8,7 +8,7 @@ organization.
|
|
|
8
8
|
|
|
9
9
|
.. _coc-when-something-happens:
|
|
10
10
|
|
|
11
|
-
When
|
|
11
|
+
When something happens
|
|
12
12
|
----------------------
|
|
13
13
|
|
|
14
14
|
If you see a Code of Conduct violation, follow these steps:
|
|
@@ -32,7 +32,7 @@ resolve the situation.
|
|
|
32
32
|
recipients of the violation over the comfort of the violator.** See
|
|
33
33
|
:ref:`some examples below <coc-enforcement-examples>`.
|
|
34
34
|
|
|
35
|
-
Our
|
|
35
|
+
Our pledge
|
|
36
36
|
----------
|
|
37
37
|
|
|
38
38
|
In the interest of fostering an open and welcoming environment, we as
|
|
@@ -43,7 +43,7 @@ identity and expression, level of experience, technical preferences,
|
|
|
43
43
|
nationality, personal appearance, race, religion, or sexual identity and
|
|
44
44
|
orientation.
|
|
45
45
|
|
|
46
|
-
Our
|
|
46
|
+
Our standards
|
|
47
47
|
-------------
|
|
48
48
|
|
|
49
49
|
Examples of behavior that contributes to creating a positive environment
|
|
@@ -112,7 +112,7 @@ to maintain the comfort and safety of its members.
|
|
|
112
112
|
|
|
113
113
|
.. _coc-other-community-standards:
|
|
114
114
|
|
|
115
|
-
Other
|
|
115
|
+
Other community standards
|
|
116
116
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
117
117
|
|
|
118
118
|
As a project on GitHub, this project is additionally covered by the
|
|
@@ -123,7 +123,7 @@ Enforcement of those guidelines after violations overlapping with the
|
|
|
123
123
|
above are the responsibility of the entities, and enforcement may happen
|
|
124
124
|
in any or all of the services/communities.
|
|
125
125
|
|
|
126
|
-
Maintainer
|
|
126
|
+
Maintainer enforcement process
|
|
127
127
|
------------------------------
|
|
128
128
|
|
|
129
129
|
Once the maintainers get involved, they will follow a documented series
|
|
@@ -133,7 +133,7 @@ members. This section covers actual concrete steps.
|
|
|
133
133
|
|
|
134
134
|
.. _coc-contacting-maintainers:
|
|
135
135
|
|
|
136
|
-
Contacting
|
|
136
|
+
Contacting maintainers
|
|
137
137
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
138
138
|
|
|
139
139
|
As a small and young project, we don't yet have a Code of Conduct
|
|
@@ -147,7 +147,7 @@ message is noticed quickly.
|
|
|
147
147
|
|
|
148
148
|
.. _coc-further-enforcement:
|
|
149
149
|
|
|
150
|
-
Further
|
|
150
|
+
Further enforcement
|
|
151
151
|
~~~~~~~~~~~~~~~~~~~
|
|
152
152
|
|
|
153
153
|
If you've already followed the :ref:`initial enforcement steps
|
|
@@ -177,7 +177,7 @@ in any social setting that puts our members at risk.
|
|
|
177
177
|
Members expelled from events or venues with any sort of paid attendance
|
|
178
178
|
will not be refunded.
|
|
179
179
|
|
|
180
|
-
Who
|
|
180
|
+
Who watches the watchers?
|
|
181
181
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
182
182
|
|
|
183
183
|
Maintainers and other leaders who do not follow or enforce the Code of
|
|
@@ -194,10 +194,10 @@ procedures.
|
|
|
194
194
|
|
|
195
195
|
.. _coc-enforcement-examples:
|
|
196
196
|
|
|
197
|
-
Enforcement
|
|
197
|
+
Enforcement examples
|
|
198
198
|
--------------------
|
|
199
199
|
|
|
200
|
-
The
|
|
200
|
+
The best case
|
|
201
201
|
~~~~~~~~~~~~~
|
|
202
202
|
|
|
203
203
|
The vast majority of situations work out like this. This interaction is
|
|
@@ -211,7 +211,7 @@ common, and generally positive.
|
|
|
211
211
|
Alex: "oh sorry, sure." -> edits old comment to say "it was really
|
|
212
212
|
confusing!"
|
|
213
213
|
|
|
214
|
-
The
|
|
214
|
+
The maintainer case
|
|
215
215
|
~~~~~~~~~~~~~~~~~~~
|
|
216
216
|
|
|
217
217
|
Sometimes, though, you need to get maintainers involved. Maintainers
|
|
@@ -248,7 +248,7 @@ something **will take priority**.
|
|
|
248
248
|
KeeperOfCommitBits: "@patt Thanks for that. I hear you on the
|
|
249
249
|
stress. Burnout sucks :/. Have a good one!"
|
|
250
250
|
|
|
251
|
-
The
|
|
251
|
+
The nope case
|
|
252
252
|
~~~~~~~~~~~~~
|
|
253
253
|
|
|
254
254
|
PepeTheFrog🐸: "Hi, I am a literal actual nazi and I think white
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Custom Fields
|
|
1
|
+
Custom fields
|
|
3
2
|
=============
|
|
4
3
|
|
|
5
4
|
There are three ways to create a custom-formatted field for a `Schema`:
|
|
@@ -10,7 +9,7 @@ There are three ways to create a custom-formatted field for a `Schema`:
|
|
|
10
9
|
|
|
11
10
|
The method you choose will depend on the manner in which you intend to reuse the field.
|
|
12
11
|
|
|
13
|
-
Creating
|
|
12
|
+
Creating a field class
|
|
14
13
|
----------------------
|
|
15
14
|
|
|
16
15
|
To create a custom field class, create a subclass of :class:`marshmallow.fields.Field` and implement its :meth:`_serialize <marshmallow.fields.Field._serialize>` and/or :meth:`_deserialize <marshmallow.fields.Field._deserialize>` methods.
|
|
@@ -43,7 +42,7 @@ To create a custom field class, create a subclass of :class:`marshmallow.fields.
|
|
|
43
42
|
created_at = fields.DateTime()
|
|
44
43
|
pin_code = PinCode()
|
|
45
44
|
|
|
46
|
-
Method
|
|
45
|
+
Method fields
|
|
47
46
|
-------------
|
|
48
47
|
|
|
49
48
|
A :class:`Method <marshmallow.fields.Method>` field will serialize to the value returned by a method of the Schema. The method must take an ``obj`` parameter which is the object to be serialized.
|
|
@@ -59,7 +58,7 @@ A :class:`Method <marshmallow.fields.Method>` field will serialize to the value
|
|
|
59
58
|
def get_days_since_created(self, obj):
|
|
60
59
|
return dt.datetime.now().day - obj.created_at.day
|
|
61
60
|
|
|
62
|
-
Function
|
|
61
|
+
Function fields
|
|
63
62
|
---------------
|
|
64
63
|
|
|
65
64
|
A :class:`Function <marshmallow.fields.Function>` field will serialize the value of a function that is passed directly to it. Like a :class:`Method <marshmallow.fields.Method>` field, the function must take a single argument ``obj``.
|
|
@@ -97,7 +96,7 @@ Both :class:`Function <marshmallow.fields.Function>` and :class:`Method <marshma
|
|
|
97
96
|
|
|
98
97
|
.. _adding-context:
|
|
99
98
|
|
|
100
|
-
Adding
|
|
99
|
+
Adding context to `Method` and `Function` fields
|
|
101
100
|
------------------------------------------------
|
|
102
101
|
|
|
103
102
|
A :class:`Function <marshmallow.fields.Function>` or :class:`Method <marshmallow.fields.Method>` field may need information about its environment to know how to serialize a value.
|
|
@@ -129,7 +128,7 @@ As an example, you might want your ``UserSchema`` to output whether or not a ``U
|
|
|
129
128
|
result["likes_bikes"] # => True
|
|
130
129
|
|
|
131
130
|
|
|
132
|
-
Customizing
|
|
131
|
+
Customizing error messages
|
|
133
132
|
--------------------------
|
|
134
133
|
|
|
135
134
|
Validation error messages for fields can be configured at the class or instance level.
|
|
@@ -160,8 +159,8 @@ Error messages can also be passed to a `Field's` constructor.
|
|
|
160
159
|
)
|
|
161
160
|
|
|
162
161
|
|
|
163
|
-
Next
|
|
162
|
+
Next steps
|
|
164
163
|
----------
|
|
165
164
|
|
|
166
|
-
- Need to add schema-level validation, post-processing, or error handling behavior? See the :doc:`Extending
|
|
165
|
+
- Need to add schema-level validation, post-processing, or error handling behavior? See the :doc:`Extending schemas <extending>` page.
|
|
167
166
|
- For example applications using marshmallow, check out the :doc:`Examples <examples>` page.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "marshmallow",
|
|
3
|
+
"package": "marshmallow",
|
|
4
|
+
"index": "_build/index.html",
|
|
5
|
+
"selectors": {
|
|
6
|
+
"dl.class dt": {
|
|
7
|
+
"type": "Class",
|
|
8
|
+
"attr": "id"
|
|
9
|
+
},
|
|
10
|
+
"dl.exception dt": {
|
|
11
|
+
"type": "Exception",
|
|
12
|
+
"attr": "id"
|
|
13
|
+
},
|
|
14
|
+
"dl.function dt": {
|
|
15
|
+
"type": "Function",
|
|
16
|
+
"attr": "id"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"icon32x32": "",
|
|
20
|
+
"allowJS": false,
|
|
21
|
+
"ExternalURL": ""
|
|
22
|
+
}
|
|
@@ -291,8 +291,8 @@ After registering a user and creating some todo items in the database, here is a
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
|
|
294
|
-
Inflection (
|
|
295
|
-
|
|
294
|
+
Inflection (camel-cased keys)
|
|
295
|
+
=============================
|
|
296
296
|
|
|
297
297
|
HTTP APIs will often use camel-cased keys for their input and output representations. This example shows how you can use the
|
|
298
298
|
`Schema.on_bind_field <marshmallow.Schema.on_bind_field>` hook to automatically inflect keys.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
.. module:: marshmallow
|
|
2
2
|
|
|
3
|
-
Extending
|
|
3
|
+
Extending schemas
|
|
4
4
|
=================
|
|
5
5
|
|
|
6
|
-
Pre-processing and
|
|
6
|
+
Pre-processing and post-processing methods
|
|
7
7
|
------------------------------------------
|
|
8
8
|
|
|
9
9
|
Data pre-processing and post-processing methods can be registered using the `pre_load <marshmallow.decorators.pre_load>`, `post_load <marshmallow.decorators.post_load>`, `pre_dump <marshmallow.decorators.pre_dump>`, and `post_dump <marshmallow.decorators.post_dump>` decorators.
|
|
@@ -97,8 +97,7 @@ One common use case is to wrap data in a namespace upon serialization and unwrap
|
|
|
97
97
|
user_objs = user_schema.load(users_data, many=True)
|
|
98
98
|
# [<User(name='Keith Richards')>, <User(name='Charlie Watts')>]
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
Raising Errors in Pre-/Post-processor Methods
|
|
100
|
+
Raising errors in pre-/post-processor methods
|
|
102
101
|
+++++++++++++++++++++++++++++++++++++++++++++
|
|
103
102
|
|
|
104
103
|
Pre- and post-processing methods may raise a `ValidationError <marshmallow.exceptions.ValidationError>`. By default, errors will be stored on the ``"_schema"`` key in the errors dictionary.
|
|
@@ -151,8 +150,7 @@ If you want to store and error on a different key, pass the key name as the seco
|
|
|
151
150
|
err.messages
|
|
152
151
|
# {'_preprocessing': ['Input data must have a "data" key.']}
|
|
153
152
|
|
|
154
|
-
|
|
155
|
-
Pre-/Post-processor Invocation Order
|
|
153
|
+
Pre-/post-processor invocation order
|
|
156
154
|
++++++++++++++++++++++++++++++++++++
|
|
157
155
|
|
|
158
156
|
In summary, the processing pipeline for deserialization is as follows:
|
|
@@ -215,10 +213,7 @@ The pipeline for serialization is similar, except that the ``pass_many=True`` pr
|
|
|
215
213
|
def step2(self, data, **kwargs):
|
|
216
214
|
do_step2(data)
|
|
217
215
|
|
|
218
|
-
|
|
219
|
-
.. _schemavalidation:
|
|
220
|
-
|
|
221
|
-
Schema-level Validation
|
|
216
|
+
Schema-level validation
|
|
222
217
|
-----------------------
|
|
223
218
|
|
|
224
219
|
You can register schema-level validation functions for a :class:`Schema` using the `marshmallow.validates_schema <marshmallow.decorators.validates_schema>` decorator. By default, schema-level validation errors will be stored on the ``_schema`` key of the errors dictionary.
|
|
@@ -245,7 +240,7 @@ You can register schema-level validation functions for a :class:`Schema` using t
|
|
|
245
240
|
err.messages["_schema"]
|
|
246
241
|
# => ["field_a must be greater than field_b"]
|
|
247
242
|
|
|
248
|
-
Storing
|
|
243
|
+
Storing errors on specific fields
|
|
249
244
|
+++++++++++++++++++++++++++++++++
|
|
250
245
|
|
|
251
246
|
It is possible to report errors on fields and subfields using a `dict`.
|
|
@@ -300,8 +295,7 @@ When multiple schema-leval validator return errors, the error structures are mer
|
|
|
300
295
|
# ]
|
|
301
296
|
# }
|
|
302
297
|
|
|
303
|
-
|
|
304
|
-
Using Original Input Data
|
|
298
|
+
Using original input data
|
|
305
299
|
-------------------------
|
|
306
300
|
|
|
307
301
|
If you want to use the original, unprocessed input, you can add ``pass_original=True`` to
|
|
@@ -332,7 +326,7 @@ If you want to use the original, unprocessed input, you can add ``pass_original=
|
|
|
332
326
|
|
|
333
327
|
The default behavior for unspecified fields can be controlled with the ``unknown`` option, see :ref:`Handling Unknown Fields <unknown>` for more information.
|
|
334
328
|
|
|
335
|
-
Overriding
|
|
329
|
+
Overriding how attributes are accessed
|
|
336
330
|
--------------------------------------
|
|
337
331
|
|
|
338
332
|
By default, marshmallow uses `utils.get_value` to pull attributes from various types of objects for serialization. This will work for *most* use cases.
|
|
@@ -350,7 +344,7 @@ However, if you want to specify how values are accessed from an object, you can
|
|
|
350
344
|
def get_attribute(self, obj, key, default):
|
|
351
345
|
return obj.get(key, default)
|
|
352
346
|
|
|
353
|
-
Custom
|
|
347
|
+
Custom error handling
|
|
354
348
|
---------------------
|
|
355
349
|
|
|
356
350
|
By default, :meth:`Schema.load` will raise a :exc:`ValidationError <marshmallow.exceptions.ValidationError>` if passed invalid data.
|
|
@@ -379,15 +373,14 @@ You can specify a custom error-handling function for a :class:`Schema` by overri
|
|
|
379
373
|
schema = UserSchema()
|
|
380
374
|
schema.load({"email": "invalid-email"}) # raises AppError
|
|
381
375
|
|
|
382
|
-
|
|
383
|
-
Custom "class Meta" Options
|
|
376
|
+
Custom "class Meta" options
|
|
384
377
|
---------------------------
|
|
385
378
|
|
|
386
379
|
``class Meta`` options are a way to configure and modify a :class:`Schema's <Schema>` behavior. See the :class:`API docs <Schema.Meta>` for a listing of available options.
|
|
387
380
|
|
|
388
381
|
You can add custom ``class Meta`` options by subclassing :class:`SchemaOpts`.
|
|
389
382
|
|
|
390
|
-
Example: Enveloping,
|
|
383
|
+
Example: Enveloping, revisited
|
|
391
384
|
++++++++++++++++++++++++++++++
|
|
392
385
|
|
|
393
386
|
Let's build upon the example above for adding an envelope to serialized output. This time, we will allow the envelope key to be customizable with ``class Meta`` options.
|
|
@@ -461,7 +454,7 @@ Our application schemas can now inherit from our custom schema class.
|
|
|
461
454
|
result = ser.dump(user)
|
|
462
455
|
result # {"user": {"name": "Keith", "email": "keith@stones.com"}}
|
|
463
456
|
|
|
464
|
-
Using
|
|
457
|
+
Using context
|
|
465
458
|
-------------
|
|
466
459
|
|
|
467
460
|
The ``context`` attribute of a `Schema` is a general-purpose store for extra information that may be needed for (de)serialization. It may be used in both ``Schema`` and ``Field`` methods.
|
|
@@ -474,7 +467,7 @@ The ``context`` attribute of a `Schema` is a general-purpose store for extra inf
|
|
|
474
467
|
schema.context["request"] = request
|
|
475
468
|
schema.dump(user)
|
|
476
469
|
|
|
477
|
-
Custom
|
|
470
|
+
Custom error messages
|
|
478
471
|
---------------------
|
|
479
472
|
|
|
480
473
|
To customize the schema-level error messages that `load <marshmallow.Schema.load>` and `loads <marshmallow.Schema.loads>` use when raising a `ValidationError <marshmallow.exceptions.ValidationError>`, override the `error_messages <marshmallow.Schema.error_messages>` class variable:
|
|
@@ -5,7 +5,7 @@ Installation
|
|
|
5
5
|
|
|
6
6
|
**marshmallow** has no external dependencies other than the `packaging` library.
|
|
7
7
|
|
|
8
|
-
Installing/
|
|
8
|
+
Installing/upgrading from the PyPI
|
|
9
9
|
----------------------------------
|
|
10
10
|
|
|
11
11
|
To install the latest stable version from the PyPI:
|
|
@@ -20,7 +20,7 @@ To install the latest pre-release version from the PyPI:
|
|
|
20
20
|
|
|
21
21
|
$ pip install -U marshmallow --pre
|
|
22
22
|
|
|
23
|
-
Get the
|
|
23
|
+
Get the bleeding edge version
|
|
24
24
|
-----------------------------
|
|
25
25
|
|
|
26
26
|
To get the latest development version of marshmallow, run
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Nesting
|
|
1
|
+
Nesting schemas
|
|
2
2
|
===============
|
|
3
3
|
|
|
4
4
|
Schemas can be nested to represent relationships between objects (e.g. foreign key relationships). For example, a ``Blog`` may have an author represented by a User object.
|
|
@@ -63,7 +63,7 @@ The serialized blog will have the nested user representation.
|
|
|
63
63
|
|
|
64
64
|
.. _specifying-nested-fields:
|
|
65
65
|
|
|
66
|
-
Specifying
|
|
66
|
+
Specifying which fields to nest
|
|
67
67
|
-------------------------------
|
|
68
68
|
|
|
69
69
|
You can explicitly specify which attributes of the nested objects you want to (de)serialize with the ``only`` argument to the schema.
|
|
@@ -129,7 +129,7 @@ You can replace nested data with a single value (or flat list of values if ``man
|
|
|
129
129
|
|
|
130
130
|
.. _partial-loading:
|
|
131
131
|
|
|
132
|
-
Partial
|
|
132
|
+
Partial loading
|
|
133
133
|
---------------
|
|
134
134
|
|
|
135
135
|
Nested schemas also inherit the ``partial`` parameter of the parent ``load`` call.
|
|
@@ -165,7 +165,7 @@ You can specify a subset of the fields to allow partial loading using dot delimi
|
|
|
165
165
|
|
|
166
166
|
.. _two-way-nesting:
|
|
167
167
|
|
|
168
|
-
Two-way
|
|
168
|
+
Two-way nesting
|
|
169
169
|
---------------
|
|
170
170
|
|
|
171
171
|
If you have two objects that nest each other, you can pass a callable to `Nested <marshmallow.fields.Nested>`.
|
|
@@ -258,7 +258,7 @@ This is useful for avoiding circular imports when your schemas are located in di
|
|
|
258
258
|
|
|
259
259
|
.. _self-nesting:
|
|
260
260
|
|
|
261
|
-
Nesting
|
|
261
|
+
Nesting a schema within itself
|
|
262
262
|
------------------------------
|
|
263
263
|
|
|
264
264
|
If the object to be marshalled has a relationship to an object of the same type, you can nest the `Schema` within itself by passing a callable that returns an instance of the same schema.
|
|
@@ -303,7 +303,7 @@ If the object to be marshalled has a relationship to an object of the same type,
|
|
|
303
303
|
# }
|
|
304
304
|
# }
|
|
305
305
|
|
|
306
|
-
Next
|
|
306
|
+
Next steps
|
|
307
307
|
----------
|
|
308
308
|
|
|
309
309
|
- Want to create your own field type? See the :doc:`Custom Fields <custom_fields>` page.
|