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

Querying of sparse fieldsets does not work #209

Open
joe-at-siemens opened this issue Sep 14, 2021 · 1 comment
Open

Querying of sparse fieldsets does not work #209

joe-at-siemens opened this issue Sep 14, 2021 · 1 comment

Comments

@joe-at-siemens
Copy link

The 'only' attribute is set only after the schema has been instantiated in the compute_schema method, and so the set of attributes that are then returned in the dump method has already been determined.

@joe-at-siemens
Copy link
Author

A workaround is to make a call to _init_fields() after schema.only is set:

if schema.opts.type_ in qs.fields:
        tmp_only = set(schema.declared_fields.keys()) & set(qs.fields[schema.opts.type_])
        if schema.only:
            tmp_only &= set(schema.only)
        schema.only = tuple(tmp_only)

        # make sure again that id field is in only parameter unless marshamllow will raise an Exception
        if schema.only is not None and 'id' not in schema.only:
            schema.only += ('id',)
        schema._init_fields()

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

1 participant