Repository navigation
django,sqlalchemy: Fix SubFactory get_or_create - #1164
Open
francoisfreitag wants to merge 3 commits into
Open
francoisfreitag wants to merge 3 commits into
francoisfreitag wants to merge 3 commits into
Conversation
francoisfreitag
force-pushed
the
get_or_create
branch
from
November 9, 2026 22:03
12d8cc0 to
a2599ea
Compare
francoisfreitag
commented
Nov 9, 2026
Comment on lines
-1165
to
-1171
| """ | ||
| In factory.django.DjangoModelFactory._get_or_create | ||
| _original_params can give some trouble when None | ||
|
|
||
| This test case verifies if the IntegrityError is correctly re-raised | ||
| """ | ||
|
|
Member
Author
There was a problem hiding this comment.
With the removal of _original_params, this docstring had no value and was removed.
Previously, the _get_or_create behavior was shoehorned into _create. Doing so lost the initial lookup provided by the user, which was solved with 077174d, saving the kwargs passed to _generate. However, SubFactory do not go through _generate, they are instantiated from the StepBuilder. To access the StepBuilder context, choose a different instantiation path for Factory subclasses that support a get_or_create behavior. Thanks to @inchang-ing for the test cases.
francoisfreitag
force-pushed
the
get_or_create
branch
from
November 10, 2026 06:56
a2599ea to
6739634
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, the
_get_or_createbehavior was shoehorned into_create.Doing so lost the initial lookup provided by the user, which was solved
with 077174d, saving the
kwargspassedto
_generate.However,
SubFactorydo not go through_generate, they are instantiatedfrom the
StepBuilder.To access the
StepBuildercontext, choose a different instantiation pathfor Factory subclasses that support a
get_or_createbehavior.Thanks to @inchang-ing for the test cases.