-
-
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
Multiple calls to prepare_recipe() within SimpleTestCase fails when recipe uses seq() #132
Comments
Hi @abbottc thanks for opening this issue. Actually, you're right about this not being able to be fixed. There's a hack to "reset" the This is being explicitly tested by 2 test methods at The decision behind this was to not add extra parameters to So, given this context, I totally agree with you that a comment on bakery's limitation to not be used with Happy baking =} |
Hi @berinhard, Thanks for following up on the issue and for the detail in explaining the rationale behind the query that gets executed in this scenario. If you'd like me to submit a PR making the minor doc addition, let me know. |
Sure, that would be great! |
Thanks, the PR is up. |
@berinhard Also, thinking about what you explained regarding the query led me to consider other issues related to that which could be considered less minor than this issue, and I've documented an example in #209. |
It doesn't seem possible to create multiple model instances using separate calls to
prepare_recipe()
within aSimpleTestCase
if the recipe usesseq()
. This triggers a database call tom.objects.count()
in https://github.com/model-bakers/model_bakery/blob/main/model_bakery/recipe.py#L37 which is disallowed inside aSimpleTestCase
.I didn't find this issue documented anywhere, although I may have missed it. It seems at least surprising if not a bug to have a database call in
prepare_recipe()
since the purpose of that method is to instantiate but not save a model instance. If it turns out this is not fixable, perhaps adding documentation regarding this caveat is appropriate.Expected behavior
The
prepare_recipe()
method is always usable withinSimpleTestCase
.Actual behavior
The use of
prepare_recipe()
withinSimpleTestCase
fails when the recipe contains aseq()
and is called more than once.Reproduction Steps
Versions
Python: 3.8.6
Django: 3.0.11
Model Bakery: 1.2.1
The text was updated successfully, but these errors were encountered: