Skip to content
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

Fix load parameter *unknow* propagation #1429

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

lmignon
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

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
@lmignon
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

@sloria sloria requested a review from deckar01 November 26, 2019 14:53
@deckar01
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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