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
A clear and concise description of what the bug is.
django_get_or_create does not work when using custom model manger create method
To Reproduce
Share how the bug happened:
Override the default model manager create method with your custom method
Define the django_get_or_create fields in the Meta class. These fields should be unique fields in the Model as well as Factory definition
Try create an instance of the factory two times with same values for the unique fields. Second time, the operation would fail giving unique constraint error.
Add any notes you feel relevant here :)
The expected behavior should be that it should try to get the instance using the django_get_or_create fields no matter if any custom manager method is defined.
The text was updated successfully, but these errors were encountered:
The default behaviour of DjangoModelFactory's _create is to hook into the object's manager's get_or_create call if required, or to use that default manager's create() block.
Is there a reason for overriding the _create() block (thus bypassing that behaviour)?
If your custom manager's get_or_create should NOT be called from the factory, you will have to override both the _create() method AND the _get_or_create() one; factory_boy cannot guess which non-standard method to call!
Description
A clear and concise description of what the bug is.
django_get_or_create does not work when using custom model manger create method
To Reproduce
Share how the bug happened:
django_get_or_create
fields in the Meta class. These fields should be unique fields in the Model as well as Factory definitionModel / Factory code
Factory
Model
The issue
Add a short description along with your code
user1 = VKUserFactory(email=vkuser0@vk.com)
user2 = VKUserFactory(email=vkuser0@vk.com)
Notes
Add any notes you feel relevant here :)
The expected behavior should be that it should try to get the instance using the
django_get_or_create
fields no matter if any custom manager method is defined.The text was updated successfully, but these errors were encountered: