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 "only" with Relationship fields using marshmallow 2.15.1 #101

Closed
mdodsworth opened this issue Apr 26, 2018 · 1 comment
Closed

fix "only" with Relationship fields using marshmallow 2.15.1 #101

mdodsworth opened this issue Apr 26, 2018 · 1 comment

Comments

@mdodsworth
Copy link
Collaborator

This change made in Marshmallow 2.15.1 changes behaviour when the caller is passing through only=():

marshmallow-code/marshmallow@98f2b47#diff-035365c88325ed9779fcb020f7bcb35a

Previously, only=() essentially meant no filtering is applied; after the change, only=() results in all fields being filtered.

Here, we're defaulting the value of only to be (), which then results in all fields being filtered (incl. id). https://github.com/marshmallow-code/marshmallow-jsonapi/blob/dev/marshmallow_jsonapi/fields.py#L104

This causes a bunch of tests to fail with issues similar to this:

self = <CommentSchema(many=False, strict=False)>, args = (), kwargs = {'exclude': (), 'only': ()}

    def __init__(self, *args, **kwargs):
        self.include_data = kwargs.pop('include_data', ())
        super(Schema, self).__init__(*args, **kwargs)
        if self.include_data:
            self.check_relations(self.include_data)

        if not self.opts.type_:
            raise ValueError('Must specify type_ class Meta option')

        if 'id' not in self.fields:
>           raise ValueError('Must have an `id` field')
E           ValueError: Must have an `id` field
@mdodsworth mdodsworth changed the title fix only with Relationship fields using marshmallow 2.15.1 fix "only with Relationship fields using marshmallow 2.15.1 Apr 27, 2018
@mdodsworth mdodsworth changed the title fix "only with Relationship fields using marshmallow 2.15.1 fix "only" with Relationship fields using marshmallow 2.15.1 Apr 27, 2018
@rgant
Copy link
Collaborator

rgant commented Apr 27, 2018

The change in marshmallow-code/marshmallow#772 broke my environment as well. Thanks @mdodsworth this fixed the issue in all of my test cases.

@sloria sloria closed this as completed in c984422 Apr 29, 2018
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

No branches or pull requests

2 participants