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

Get ManyToOneRel fields (reverse FK) back to work #300

Merged
merged 7 commits into from Mar 31, 2022
Merged

Get ManyToOneRel fields (reverse FK) back to work #300

merged 7 commits into from Mar 31, 2022

Conversation

berinhard
Copy link
Member

Fixes #291

Given the way Django's Model.save() works, the code was breaking when trying to prepared (via baker.prepare) objects which hold FK for other prepared instances. The save call only persists the current model and not the subsequent ones.

Meanwhile, django manager's set or add methods does handle nested persistence, but doesn't know how to save models which doesn't hold other FKs (or at least this is what I understood from the issue).

So, this PR introduces a fixes to only save an object before adding it to the related model if it doesn't have any FK. Other scenarios should now be handled by Django

@berinhard berinhard requested review from timjklein36, amureki and a team March 31, 2022 21:57
Copy link
Collaborator

@timjklein36 timjklein36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid, just had some grammar suggestions.

model_bakery/baker.py Outdated Show resolved Hide resolved
tests/generic/models.py Outdated Show resolved Hide resolved
berinhard and others added 2 commits March 31, 2022 19:33
Co-authored-by: Tim Klein <timjklein36@gmail.com>
Co-authored-by: Tim Klein <timjklein36@gmail.com>
@berinhard
Copy link
Member Author

Thanks for the fixes @timjklein36! As a non english speaker, they are always welcome =)

@berinhard berinhard merged commit 42bc039 into main Mar 31, 2022
@berinhard berinhard deleted the issue291 branch March 31, 2022 22:45
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.

ManyToOneRel fields (reverse FK) are broken in 1.3.3
2 participants