Comments (2)
I'd be willing to discuss adding partial: bool | None
as an argument to use_args
, use_kwargs
, and parse
in a separate issue, if that's a desirable feature. Likewise for any other arguments to Schema.load
But I'll say up front that I'm -0 on it because there's a viable workaround and it could easily really mess up use_kwargs
usage.
With that out of the way, I'm going to close this because it's a question which I believe I've answered sufficiently. If there's anything which is still unclear, please feel free to ask for more detail.
from webargs.
webargs
doesn't have support for passing all of the potential arguments for Schema.load
, so you can't do this directly. What you can do, however, is take advantage of the fact that partial
defaults to whatever value is set on the schema instance used. That means that if you use a schema object instead of a dict for use_kwargs
, you can set partial
on it.
To isolate this problem from your surrounding context a bit, consider this simpler schema + webargs usage:
import marshmallow as ma
from webargs.flaskparser import use_args # any parser, flask as an example
class Point(ma.Schema):
x = ma.fields.Int(required=True)
y = ma.fields.Int(required=True)
@use_args({"start": ma.fields.Nested(Point()), "end": ma.fields.Nested(Point())})
def foo(segment):
...
To set partial=True
on the schema, you won't be able to use the dict form. Instead, create a dedicated schema and set partial=True
on it when you instantiate it:
class Segment(ma.Schema):
start = ma.fields.Nested(Point())
end = ma.fields.Nested(Point())
@use_args(Segment(partial=True))
def foo(segment):
...
I'd recommend use_args
or parse
rather than use_kwargs
if you do this though. partial=True
means that fields could be missing and therefore not passed as arguments via use_kwargs
.
This isn't the only solution to partial loading. The major alternative, one which I would recommend considering, is to use a schema factory function to create your schemas with the desired settings. e.g.
def make_point_schema(*, partial=False):
class Point(ma.Schema):
x = ma.fields.Int(required=not partial)
y = ma.fields.Int(required=not partial)
return Point
Point = make_point_schema()
PartialPoint = make_point_schema(partial=True)
I prefer this over partial=True/False
because it offers much finer grained control. But it is a bit more verbose.
I'm not sure what we should do about not being able to use partial
as a parameter to Schema.load
. We could add support, and it wouldn't be too hard to do so. But it complicates the interface, and it is a relatively niche case. I don't know that, given that we haven't seen frequent requests for it, we should add support.
from webargs.
Related Issues (20)
- [RFC] Revisiting our CI setup: GH Actions, RTD HOT 8
- potential documentation issue in quickstart/error-handling HOT 3
- Parse a schema that contains both file and form data HOT 2
- How to strip empty strings from list of strings in args using DjangoParser? HOT 3
- Tags cleanup HOT 2
- When setting location to `files`, custom field's `_deserialize` and `_validated` methods were not called HOT 7
- aiohttp. body argument is deprecated for http web exceptions HOT 1
- Update minimum supported versions of frameworks in next major release HOT 1
- Release version 8.2.0 HOT 4
- [Question] how to use this with line item like data? HOT 2
- Is there possible add Quixote web framework support HOT 2
- [Question] How to set up the Schema that will validate against a list of allowed enum values? HOT 1
- Dealing with empty values in `DelimitedFieldMixin` HOT 2
- Being able to handle ValidationError in Flask view methods without custom error handler HOT 4
- webargs.core.Parser should describe default for unknown either as marshmallow.EXCLUDE or "exclude" HOT 1
- RFC: support passing the whole parsed arguments as a keyword argument HOT 10
- Please consider using Mapping instead of Dict in ArgsMap to avoid type checker errors HOT 7
- Parse schema without using decorators HOT 1
- How to handle JSON data always nested / wrapped in a "body" object HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webargs.