-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
[BUG] baker.make() dunder syntax fails for through-table model in 1.3.3 #273
Comments
@cb109 thank you for providing such a detailed report and a PR with a test. Much appreciated! I suspect https://github.com/model-bakers/model_bakery/pull/207/files#diff-e5857deb915e241f429a0c118e89e06a3388d3ce1466e3aa4b960b7055172b6dL322 to be the reason for this bug, but not yet sure how to tackle it. Before I try to dig into it, @timjklein36 @berinhard, do you have ideas? |
@amureki I don't have any ideas without looking into it further. |
I did some experimental changes, all tests (model_bakery + our own testsuite) pass when I change def get_related(
self,
) -> List[Union[ManyToOneRel, OneToOneRel]]:
return [r for r in self.model._meta.related_objects if not r.many_to_many] into def get_related(
self,
) -> List[Union[ManyToOneRel, OneToOneRel, ManyToManyRel]]:
return [r for r in self.model._meta.related_objects] That's probably not desired, but maybe it helps figuring out a solution, just wanted to mention what I observed. |
Since I just updated our codebase to use 1.5.0 just wanted to leave a quick feedback that the issue indeed seems to be solved and all our own tests are passing again 👍 |
The v1.3.3 release broke a few of our tests where we use model_bakery's "dunder syntax" to specify fields on ForeignKeys on a through-table model.
I am able to reproduce it in a minimal example, but have no clue yet how to fix it, hoping you can point me in the right direction.
Expected behavior
baker.make()
should create the through-table model instance with instances in both ForeignKey fields as specified.Actual behavior
Model instance creation fails with:
Reproduction Steps
Given these models:
Failure can be reproduced via:
Versions
Python: 3.8.10
Django: 2.2.24
Model Bakery: 1.3.3
Notes
content
orplayer
directly (e.g.content=content_instance
) in the example above will make the problem disappear, it only comes up when both fields are passed with the dunder syntax.playlist
ManyToManyField
with thethrough
Option will also make the problem disappear.The text was updated successfully, but these errors were encountered: