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

Duplicate the context hash when duplicating an Attacher #653

Merged
merged 1 commit into from
Sep 17, 2023

Conversation

reidab
Copy link
Contributor

@reidab reidab commented Sep 8, 2023

We hit an issue following the upgrade to 3.5.0 where context[:record] in an Attacher#finalize call was set to an unpersisted duplicate of the record we were saving. This turned out to be because another part of our model save flow was duplicating the model for its own purposes and the context hash was shared between the original attacher and its duplicate.

The changes in fc6a3ed added a call to attacher_copy.set_entity(self, name) if attacher_copy. Because @context in both attachers point at the same object, this ends up with context[:record] for both records pointing to the new duplicate model.

Without this change, a single context hash is shared between the original attacher and its duplicate. The changes in fc6a3ed update this shared hash after duplication to reference the duplicate model, leading to both the duplicate and original attacher having `context[:record]` pointing at the duplicated model.
@janko
Copy link
Member

janko commented Sep 17, 2023

Thanks for the patch, looks good 👍🏻

@janko janko merged commit bf43c6d into shrinerb:master Sep 17, 2023
9 checks passed
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.

2 participants