You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File "python3.12/site-packages/model_bakery/baker.py", line 131, in make
return bulk_create(baker, _quantity, _save_kwargs=_save_kwargs, **attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "python3.12/site-packages/model_bakery/baker.py", line 840, in bulk_create
through_model(
File "python3.12/site-packages/django/db/models/base.py", line 567, in __init__
raise TypeError(
TypeError: MyUserGroupMembership() got unexpected keyword arguments: 'users', 'mygroup'
Obviously these fields are not valid to create an instance of MyUserGroupMembership.
The offending code in bakery is in baker.bulk_create:
You can see that the arguments used to create the through model are field.remote_field.name and field.related_model._meta.model_name. These are incorrect as shown above and need to be fixed.
Maybe through fields are best used for this (or pose an additional complication, not sure without further digging).
Expected behavior
Bakery can actually bulk create models that are using ManyToManyField with a through attribute.
Versions
Python: 3.12
Django 4.2
Model Bakery 1.18.0
The text was updated successfully, but these errors were encountered:
Describe the issue
Bakery fails with an exception when trying to bulk create models that are using ManyToManyField with a
through
attribute.To Reproduce
Suppose you have models like these:
And then you run code similar to
You will receive an exception like this:
Obviously these fields are not valid to create an instance of
MyUserGroupMembership
.The offending code in bakery is in
baker.bulk_create
:You can see that the arguments used to create the
through
model arefield.remote_field.name
andfield.related_model._meta.model_name
. These are incorrect as shown above and need to be fixed.Maybe through fields are best used for this (or pose an additional complication, not sure without further digging).
Expected behavior
Bakery can actually bulk create models that are using ManyToManyField with a
through
attribute.Versions
The text was updated successfully, but these errors were encountered: