@@ -11,15 +11,15 @@ Multiple Locations Are No Longer Supported In A Single Call
11
11
12
12
The default location is JSON/body.
13
13
14
- Under webargs 5.x, you may have written code which did not specify a location.
14
+ Under webargs 5.x, code often did not have to specify a location.
15
15
16
- Because webargs would parse data from multiple locations automatically, you did
17
- not need to specify where a parameter, call it `q `, was passed.
16
+ Because webargs would parse data from multiple locations automatically, users
17
+ did not need to specify where a parameter, call it `q `, was passed.
18
18
`q ` could be in a query parameter or in a JSON or form-post body.
19
19
20
- Now, webargs requires that you specify only one location for data loading per
20
+ Now, webargs requires that users specify only one location for data loading per
21
21
`use_args ` call, and `"json" ` is the default. If `q ` is intended to be a query
22
- parameter, you must be explicit and rewrite like so:
22
+ parameter, the developer must be explicit and rewrite like so:
23
23
24
24
.. code-block :: python
25
25
@@ -34,9 +34,9 @@ parameter, you must be explicit and rewrite like so:
34
34
def foo (args ):
35
35
return some_function(user_query = args.get(" q" ))
36
36
37
- This also means that another usage from 5.x is not supported. If you had code
38
- with multiple locations in a single `use_args `, `use_kwargs `, or `parse ` call,
39
- you must write it in multiple separate `use_args ` or `use_kwargs ` invocations,
37
+ This also means that another usage from 5.x is not supported. Code with
38
+ multiple locations in a single `use_args `, `use_kwargs `, or `parse ` call
39
+ must be rewritten in multiple separate `use_args ` or `use_kwargs ` invocations,
40
40
like so:
41
41
42
42
.. code-block :: python
@@ -87,9 +87,11 @@ location_handler Has Been Replaced With location_loader
87
87
This is not just a name change. The expected signature of a `location_loader `
88
88
is slightly different from the signature for a `location_handler `.
89
89
90
- Where previously your code took the incoming request data and details of a
91
- single field being loaded, it now takes the request and the schema as a pair.
92
- It does not return a specific field's data, but data for the whole location.
90
+ Where previously a `location_handler ` code took the incoming request data and
91
+ details of a single field being loaded, a `location_loader ` takes the request
92
+ and the schema as a pair. It does not return a specific field's data, but data
93
+ for the whole location.
94
+
93
95
Rewrite code like this:
94
96
95
97
.. code-block :: python
@@ -105,8 +107,8 @@ Rewrite code like this:
105
107
def load_data (request , schema ):
106
108
return request.data
107
109
108
- Data Is Not Filtered Before Being Passed To Your Schema , And It May Be Proxified
109
- --------------------------------------------------------------------------------
110
+ Data Is Not Filtered Before Being Passed To Schemas , And It May Be Proxified
111
+ ----------------------------------------------------------------------------
110
112
111
113
In webargs 5.x, the deserialization schema was used to pull data out of the
112
114
request object. That data was compiled into a dictionary which was then passed
@@ -117,16 +119,8 @@ on schemas. This lets a schema decide what to do with fields not specified in
117
119
the schema. In order to achieve this, webargs now passes the full data from
118
120
the specified location to the schema.
119
121
120
- However, many types of request data are so-called "multidicts" -- dictionary-like
121
- types which can return one or multiple values as you prefer. To handle
122
- `marshmallow.fields.List ` and `webargs.fields.DelimitedList ` fields correctly,
123
- passing list data, webargs must combine schema information with the raw request
124
- data. This is done in the
125
- :class: `MultiDictProxy <webargs.multidictproxy.MultiDictProxy> ` type, which
126
- will often be passed to your schemas.
127
-
128
- Therefore, you should specify `unknown=marshmallow.EXCLUDE ` on your schemas if
129
- you want to filter out unknown fields. Like so:
122
+ Therefore, users should specify `unknown=marshmallow.EXCLUDE ` on their schemas in
123
+ order to filter out unknown fields. Like so:
130
124
131
125
.. code-block :: python
132
126
@@ -161,8 +155,7 @@ you want to filter out unknown fields. Like so:
161
155
...
162
156
163
157
164
- This also allows you to write code which passes the unknown parameters through,
165
- like so:
158
+ This also allows usage which passes the unknown parameters through, like so:
166
159
167
160
.. code-block :: python
168
161
@@ -177,11 +170,17 @@ like so:
177
170
...
178
171
179
172
180
- Finally, this change passes a proxy object where you once saw a dict. This
181
- means that if your schema has a `pre_load ` hook which interacts with the data,
173
+ However, many types of request data are so-called "multidicts" -- dictionary-like
174
+ types which can return one or multiple values. To handle `marshmallow.fields.List `
175
+ and `webargs.fields.DelimitedList ` fields correctly, passing list data, webargs
176
+ must combine schema information with the raw request data. This is done in the
177
+ :class: `MultiDictProxy <webargs.multidictproxy.MultiDictProxy> ` type, which
178
+ will often be passed to schemas.
179
+
180
+ This means that if a schema has a `pre_load ` hook which interacts with the data,
182
181
it may need modifications. For example, a `flask ` query string will be parsed
183
182
into an `ImmutableMultiDict ` type, which will break pre-load hooks which modify
184
- the data in-place. You may need to apply rewrites like so:
183
+ the data in-place. Such usages need rewrites like so:
185
184
186
185
.. code-block :: python
187
186
@@ -231,8 +230,8 @@ DelimitedList Now Only Takes A String Input
231
230
-------------------------------------------
232
231
233
232
Combining `List ` and string parsing functionality in a single type had some
234
- messy corner cases. For the most part, this should not require rewrites. But if
235
- you need to allow both usages in your API, you can do a rewrite like so:
233
+ messy corner cases. For the most part, this should not require rewrites. But
234
+ for APIs which need to allow both usages, rewrites are possible like so:
236
235
237
236
.. code-block :: python
238
237
@@ -274,14 +273,14 @@ you need to allow both usages in your API, you can do a rewrite like so:
274
273
ValidationError Messages Are Namespaced Under The Location
275
274
----------------------------------------------------------
276
275
277
- If you were parsing ValidationError messages, you will notice a change in the
278
- messages produced by webargs.
276
+ Code parsing ValidationError messages will notice a change in the messages
277
+ produced by webargs.
279
278
What would previously have come back with messages like `{"foo":["Not a valid integer."]} `
280
279
will now have messages nested one layer deeper, like
281
280
`{"json":{"foo":["Not a valid integer."]}} `.
282
281
283
- To rewrite code which was handling these errors, you will need to be prepared
284
- to traverse messages by one additional level. For example:
282
+ To rewrite code which was handling these errors, the handler will need to be
283
+ prepared to traverse messages by one additional level. For example:
285
284
286
285
.. code-block :: python
287
286
0 commit comments