You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.rst
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
Changelog
2
2
---------
3
3
4
+
1.1.0 (unreleased)
5
+
******************
6
+
7
+
Features:
8
+
9
+
* ``Parser.parse``, ``Parser.use_args`` and ``Parser.use_kwargs`` can take a Schema factory as the first argument (:issue:`73`). Thanks :user:`DamianHeard` for the suggestion and the PR.
Copy file name to clipboardExpand all lines: docs/quickstart.rst
+77-2Lines changed: 77 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -214,8 +214,8 @@ Nesting Fields
214
214
})
215
215
}
216
216
217
-
Marshmallow Integration
218
-
-----------------------
217
+
Advanced: Marshmallow Integration
218
+
---------------------------------
219
219
220
220
When you need more flexibility in defining input schemas, you can pass a marshmallow `Schema <marshmallow.Schema>` instead of a dictionary to `Parser.parse <webargs.core.Parser.parse>`, `Parser.use_args <webargs.core.Parser.use_args>`, and `Parser.use_kwargs <webargs.core.Parser.use_kwargs>`.
221
221
@@ -254,6 +254,81 @@ When you need more flexibility in defining input schemas, you can pass a marshma
254
254
.. note::
255
255
You should always set ``strict=True`` (either as a ``class Meta`` option or in the Schema's constructor) when passing a schema to webargs. This will ensure that the parser's error handler is invoked when expected.
256
256
257
+
258
+
Advanced: Schema Factories
259
+
--------------------------
260
+
261
+
If you need to parametrize a schema based on a given request, you can use a "Schema factory": a callable that receives the current `request` and returns a `marshmallow.Schema` instance.
262
+
263
+
Consider the following use cases:
264
+
265
+
- Handle partial updates for PATCH requests using marshmallow's `partial loading <https://marshmallow.readthedocs.org/en/latest/quickstart.html#partial-loading>`_ API.
266
+
- Filtering via a query parameter by passing ``only`` to the Schema.
0 commit comments