-
Notifications
You must be signed in to change notification settings - Fork 399
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
django_get_or_create with SubFactory #979
Comments
That's surprising, the error message you mention doesn't seem to match the existing codebase (neither |
I'm using the |
In my project a model has an unique char field of two characters. The factory fills this fields with a |
Ok, took some time to provide a failing testcase (forgive me for the bad naming). Do you agree that the problem can be solved by initiating the class attribute |
The test case exhibits the problem well, thank you, it’s very helpful! 🎉
I do not agree. |
Thanks for providing some context! Checking for |
Description
The django_get_or_create feature is working well when the concerned Factory is used as a BaseFactory but not when it's used as a SubFactory
When used as a SubFactory, the following error occurs :
AttributeError: type object 'CurrencyFactory' has no attribute '_original_params'
To Reproduce
With the below code, the error will occur randomly when the same currency code/name is used.
To reproduce it systematically, just change the PairFactory with the following line :
It will force the IntegrityError in the Currency Factory, so it will try the get_or_create feature.
And then call the PairFactory() two times and voila.
Model / Factory code
Notes
I believe this is linked to the _generate() method which is not called for SubFactory, while the _original_params is set only in this method.
The text was updated successfully, but these errors were encountered: