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

"transient" setting not shared with nested schemas #206

Closed
MattF-NSIDC opened this issue Apr 29, 2019 · 1 comment · Fixed by #246

Comments

@MattF-NSIDC
Copy link

commented Apr 29, 2019

Exactly like #67 for sharing "session" with nested child schemas, but with "transient" instead!

My fix for both issues in one snippet:

class BaseModelSchema(ModelSchema):
    OPTIONS_CLASS = BaseOpts

    @mm.pre_load
    def set_nested_attrs(self, data: Data) -> Data:
        """Allow nested schemas to use the parent schema's attrs. This is a
        longstanding bug with marshmallow-sqlalchemy.

        https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues/67
        https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues/206
        https://github.com/marshmallow-code/marshmallow/issues/658#issuecomment-328369199
        """
        nested_fields = {k: v for k, v in self.fields.items() if type(v) == mm.fields.Nested}
        for field in nested_fields.values():
            field.schema.session = self.session
            field.schema.transient = self.transient

        return data
@sloria

This comment has been minimized.

Copy link
Member

commented Sep 5, 2019

This should be easier to fix now that marshmallow_sqlalcemy.fields.Nested fixed the session behavior. We just need to do the same for transient. PRs for this welcome.

@sloria sloria added the help wanted label Sep 5, 2019

sloria added a commit that referenced this issue Sep 6, 2019
sloria added a commit that referenced this issue Sep 6, 2019

@sloria sloria closed this in #246 Sep 6, 2019

sloria added a commit that referenced this issue Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.