Closed rubnov closed 7 months ago
Same issue here. Any idea how to fix it?
@matejkloska Can you post a minimal code example reproducing the issue?
@rubnov Can you try it in a minimal script without using pytest-factory_boy? The way fixtures are injected by pytest makes reasoning about the code path quite harder...
I have this same problem, any update?
hi, some news. After many time trying fix, i notice my mistake is because i changed method save in model for calling super save twice in one only call for save
In my case, I have a call to super().save(*args, **kwargs)
within the User.save()
method. It is intentional, not a mistake, and I really do need it to establish M2M relations. But now I've discovered that it's broken my UserFactory, and am not sure how to proceed.
Same issue here... this still isn't fixed.
@rubnov sorry for the very late response, but the issue stemmed from this line:
save = factory.PostGenerationMethodCall('save')
It did cause a second .save()
, which might cause issues with your overridden def save(...)
; moreover, that extra method call isn't required, as factory.django.DjangoModelFactory
will automatically call .save()
after all PostGenerationMethodCall
s have run.
For other participants to this discussion, this error came from a specific implementation of the factory; which is unlikely to be the cause of the error you would see. Could you please open new issues with your specific code and stacktrace? This will allow us to look into each special case specifically.
Thanks!
Closed for inactivity.
Description
Following a dependency update of my Django project (django, factory_boy, pytest-factoryboy), a lot of my tests are failing with a
duplicate key
error.The error occurs when using a
user
fixture based on a UserFactory. For some reason factory_boy is callingcreate()
twice on the object with the same primary_key, and I cannot understand why or what is causing this.To Reproduce
Model / Factory code
The issue
Add a short description along with your code One example failing test is
test_auth_broken_check_hmac_expected_user_id
below:Stack Trace:
Notes
The code above worked before updating the dependencies, which puzzles me. To be honest this was a major update from Django 1.11 to 2.2.6, along with factory_boy from 2.5.2 to 2.12.0 and pytest-factoryboy from 1.1.0 to 2.0.3.