Skip to content

django,sqlalchemy: Fix SubFactory get_or_create - #1164

Open
francoisfreitag wants to merge 3 commits into
FactoryBoy:masterfrom
francoisfreitag:get_or_create
Open

francoisfreitag wants to merge 3 commits into
FactoryBoy:masterfrom
francoisfreitag:get_or_create

Conversation

@francoisfreitag

Copy link
Copy Markdown
Member

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.

Comment thread tests/test_django.py
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
"""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant