@@ -11,15 +11,15 @@ Multiple Locations Are No Longer Supported In A Single Call
1111
1212The default location is JSON/body.
1313
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.
1515
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.
1818`q ` could be in a query parameter or in a JSON or form-post body.
1919
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
2121`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:
2323
2424.. code-block :: python
2525
@@ -34,9 +34,9 @@ parameter, you must be explicit and rewrite like so:
3434 def foo (args ):
3535 return some_function(user_query = args.get(" q" ))
3636
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,
4040like so:
4141
4242.. code-block :: python
@@ -87,9 +87,11 @@ location_handler Has Been Replaced With location_loader
8787This is not just a name change. The expected signature of a `location_loader `
8888is slightly different from the signature for a `location_handler `.
8989
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+
9395Rewrite code like this:
9496
9597.. code-block :: python
@@ -105,8 +107,8 @@ Rewrite code like this:
105107 def load_data (request , schema ):
106108 return request.data
107109
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+ ----------------------------------------------------------------------------
110112
111113In webargs 5.x, the deserialization schema was used to pull data out of the
112114request 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
117119the schema. In order to achieve this, webargs now passes the full data from
118120the specified location to the schema.
119121
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:
130124
131125.. code-block :: python
132126
@@ -161,8 +155,7 @@ you want to filter out unknown fields. Like so:
161155 ...
162156
163157
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:
166159
167160.. code-block :: python
168161
@@ -177,11 +170,17 @@ like so:
177170 ...
178171
179172
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,
182181it may need modifications. For example, a `flask ` query string will be parsed
183182into 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:
185184
186185.. code-block :: python
187186
@@ -231,8 +230,8 @@ DelimitedList Now Only Takes A String Input
231230-------------------------------------------
232231
233232Combining `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:
236235
237236.. code-block :: python
238237
@@ -274,14 +273,14 @@ you need to allow both usages in your API, you can do a rewrite like so:
274273 ValidationError Messages Are Namespaced Under The Location
275274----------------------------------------------------------
276275
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.
279278What would previously have come back with messages like `{"foo":["Not a valid integer."]} `
280279will now have messages nested one layer deeper, like
281280`{"json":{"foo":["Not a valid integer."]}} `.
282281
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:
285284
286285.. code-block :: python
287286
0 commit comments