"unknown" option should apply to nested fields so that "exclude" works
See original GitHub issueThe fact that exclude
takes dotted notation for nested fields, but unknown
does not apply to nested fields, means that exclude
doesn’t work for nested fields in some common use cases unless the nested schema(s) have the desired Meta.unknown
setting, and then they are not runtime-flexible, which is the great benefit of Schema and load
taking exclude
. Somewhat new to marshmallow so maybe there’s a way to accomplish this (setting exclude
on nested fields at load time) in a different way?
Happy to contribute a PR if you guys think this is a good idea.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
"Unknown field" after updating to 3.5.0 marshmallow
from marshmallow import EXCLUDE class UserSchema(Schema): class Meta: ... The unknown option value set in load will override the value ...
Read more >Upgrading to Newer Releases — marshmallow 3.19.0 ...
The unknown option can be passed as a Meta option, on Schema instantiation, or at load time. from marshmallow import Schema, fields, EXCLUDE,...
Read more >Nested query | Elasticsearch Guide [8.5]
Wraps another query to search nested fields. The nested query searches nested field objects as if they were indexed as separate documents.
Read more >How to Ignore Unknown Properties While Parsing JSON in ...
Jackson API provides two ways to ignore unknown fields, first at the class level using ... If you compile and run your program...
Read more >EXCLUDE Level of Detail Expressions
Applies to: Tableau Cloud, Tableau Desktop, Tableau Public, Tableau Server ... the Analytics pane wouldn't work, because it would simply be a horizontal ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
any news here?
Looking at this issue from the perspective of webargs, I see two (related) issues with #1575. I think I have a good idea of how to resolve them, but want to see if people like the results before I try to write it.
unknown
propagates automatically in any context (as in #1575), it will be backwards incompatibleunknown
behaves inconsistently betweenMeta
, schema instantiation, andload
, it will cause confusionAnd then, as an ancillary concern, if someone is writing a library on top of marshmallow (👋 hi guys!), they’ll want to be able to control this or offer control to their users.
Maybe backwards incompatibility isn’t an issue in this case – if it’s considered a bug that’s being fixed – but I think it will be a problem for someone.
So my idea:
unknown
,propagate_unknown
propagate_unknown
can beTrue
orFalse
(by default, for backwards compat) and can be removed (True
everywhere) in marshmallow v4propagate_unknown
is True, behave as in #1575 whenunknown
is passed toload
, and if False, behave as todayI would take #1575 as a basis for this work. It looks solid, has nice tests, and credit where it’s due – I just don’t quite agree with the behavior.
The downsides are that we have a new attribute to control
unknown
, which might feel messy, and that we don’t get the desired behavior by default. To me, those are worthwhile in the first case and a necessary evil in the second.You can do it all with just one attribute, but I promise that it's worse.
This is just for fun. Don’t take this suggestion seriously. Please. 😄
We could change the constants a bit…
but then we’re just asking for trouble because you have to check for
INCLUDE|EXCLUDE
, which makes no sense.