Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix load parameter *unknow* propagation #1429

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

Open
lmignon wants to merge 2 commits into marshmallow-code:dev
base: dev
Choose a base branch
Loading
from lmignon:dev-fix-deserialize-unknown-in-nested

Conversation

Copy link

@lmignon lmignon commented Oct 18, 2019

When deserializing a data structure with the load method, the unknown was not propagated to the loading of nested data structures. As result, if a unknown field was present into a nested data structure a ValidationError was raised even if the load methd was called with unknown=EXCLUDE. This commit ensures that this parameter is now propagated also to the loading of nested data structures.
fixes #1428

Sytten reacted with thumbs up emoji
When deserializing a data structure with the load method, the *unknown* was not propagated to the loading of nested data structures. As result, if a unknown field was present into a nested data structure a ValidationError was raised even if the load methd was called with *unknown=EXCLUDE*. This commit ensures that this parameter is now propagated also to the loading of nested data structures.
fixes marshmallow-code#1428 
@lmignon lmignon force-pushed the dev-fix-deserialize-unknown-in-nested branch from 3d94ded to e1acdd7 Compare November 2, 2019 11:11
Copy link
Author

lmignon commented Nov 2, 2019

@lafrech @sloria What do you thing about this proposed fix? I tried to provide the required documentation to make this behavior explicit.

Copy link

@SVilgelm SVilgelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, i have just one nit comment

Copy link

@SVilgelm SVilgelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

Copy link
Member

Nested.load() calls Schema.load() internally, so when an unknown argument is supplied to the Nested constructor, this PR causes all of the nested unknown options to be recursively overridden.

from marshmallow import fields, Schema, RAISE, INCLUDE, EXCLUDE
class C(Schema):
 foo = fields.Str()
 class Meta:
 unknown = EXCLUDE
class B(Schema):
 c = fields.Nested(C)
class A(Schema):
 b = fields.Nested(B, unknown=INCLUDE)
 class Meta:
 unknown = RAISE
schema = A()
print(schema.load({
 'b': {
 'extra': 'good',
 'c': {
 'foo': 'bar',
 'unexpected': 'bad'
 }
 }
}))

Current behavior (3.2.2):

{'b': {'c': {'foo': 'bar'}, 'extra': 'good'}}

Proposed behavior:

{'b': {'c': {'foo': 'bar', 'unexpected': 'bad'}, 'extra': 'good'}}

sirosen added a commit to sirosen/marshmallow that referenced this pull request Jul 17, 2020
The changelog entry, including credit to prior related work, covers
the closed issues and describes how `propagate_unknown` is expected to
behave.
Inline documentation attempts to strike a balance between clarify and
brevity.
closes marshmallow-code#1428, marshmallow-code#1429, marshmallow-code#1490, marshmallow-code#1575 
sirosen added a commit to sirosen/marshmallow that referenced this pull request Jul 17, 2020
The changelog entry, including credit to prior related work, covers
the closed issues and describes how `propagate_unknown` is expected to
behave.
Inline documentation attempts to strike a balance between clarify and
brevity.
closes marshmallow-code#1428, marshmallow-code#1429, marshmallow-code#1490, marshmallow-code#1575 
sirosen added a commit to sirosen/marshmallow that referenced this pull request Sep 4, 2020
The changelog entry, including credit to prior related work, covers
the closed issues and describes how `propagate_unknown` is expected to
behave.
Inline documentation attempts to strike a balance between clarify and
brevity.
closes marshmallow-code#1428, marshmallow-code#1429, marshmallow-code#1490, marshmallow-code#1575 
Copy link

bhperry commented Aug 18, 2025

Any chance of this merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@deckar01 deckar01 Awaiting requested review from deckar01

2 more reviewers

@SVilgelm SVilgelm SVilgelm approved these changes

@Sytten Sytten Sytten approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

unknown parameter passed to load method is not popagated to nested schema field.

AltStyle によって変換されたページ (->オリジナル) /