-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Default to unknown=EXCLUDE? #507
Comments
I'm realizing that my question above is based on the wrong assumption that the The question in #480 was about changing the default for I don't see a nice way to change the default in marshmallow schemas. Changing it inside user-provided schema sounds bad. Providing a base schema with But having the default in dict2schema differ from Schema sounds bad, doesn't it? |
at least there should be an option to set |
That's the point of #480 (comment). I wouldn't object to that. Well, the thing is |
I think the problem comes becuase dict object and schema class are basically two different things. I agreed with your idea that if that any attrs in |
I think the simplest solution is to just add Line 260 in 68f8d83
becomes load_kwargs = {}
if unknown is not None:
load_kwargs["unknown"] = unknown
result = schema.load(location_data, **load_kwargs) With no change in defaults for That solves it because you can specify If webargs itself adds a default for I keep on thinking up "clever" ideas, like having a |
I like the fact that it acts on both schema and dict. It might solve the bad UX of having RAISE as default while most of the time EXCLUDE is better (totally arguable) if the user can define another default value. As a matter of fact, he can by overriding parse in a subclass, but we could add a I'd rather have a custom default value (EXCLUDE) at framework level that I would override in Schema (RAISE in Schemas used in body), and see nothing in my API resources. With your solution, I can leave Schemas to default RAISE and override to EXCLUDE in each use_args query args call, but that's cumbersome and I'd rather stick to overriding unknown in the Schema (I don't use dict2schema) overall. I guess I'm not really concerned by this change since I only use Schemas and the meta attribute is well suited for my case. And therefore the good points I pointed if not this whole comment are not that relevant... What about propagation? Currently, unknown does not propagate. It may change in the near future. marshmallow-code/marshmallow#1575 I guess propagation affects mostly body payloads for which people mostly use Schemas. |
I don't really like this solution because it's mixing things together in a way that I believe is likely to be a source of confusion for users. It also poses a problem when, for example, We have to draw a line somewhere on how many features will be packed into dict2schema usage.
Yeah, many people will want I agree with your point about having to specify So what about adding both of these things?
with logic like We could add |
Oh, I forgot to answer about propagation. I'm not sure what, if anything, we would do differently to handle it in webargs? It might fall on the other side of the "if you want that, use a Schema class" divide. The way that marshmallow PR is written, it looks like the proposal would be to propagate the |
I'm fine with whatever |
This is done in dev and will be part of the 7.0.0 release. It's available in the current beta. For anyone reading this thread: we went with a per-location approach after all. |
Question raised in #480.
unknown=RAISE
may be a nice default in marshmallow but it can be cumbersome to change in webargs.In practice it is mostly useful in body payload.
I wouldn't use it in query args, for instance, because by construction of the framewok, there may be several layers of decorators adding different fields to parse.
In flask-smorest, I added a doc section to explain it but it is still surprising for the user (see marshmallow-code/flask-smorest#145).
While the base schema is the way to go in marshmallow and is convenient once you are familiar with this logic, it is not practical to with arguments defined with
dict2schema
.I guess in practice,
dict2schema
is used mostly for arguments with a few fields (typically query args) while the schema form is adapted to huge schemas (typically json body). UsingEXCLUDE
as default would make thedict2field
form work while the user could easily opt-in toRAISE
when using the schema form.Should we change the default to
EXCLUDE
in a major release and let the user opt-in toRAISE
?The text was updated successfully, but these errors were encountered: