factory_boy icon indicating copy to clipboard operation
factory_boy copied to clipboard

Add unique_constraints, a more versatile replacement for django_get_or_create and sqlalchemy_get_or_create

Open rbarrois opened this issue 5 years ago • 2 comments

This change deprecates django_get_or_create and sqlalchemy_get_or_create; upgrade helpers are provided through a newly-introduced option renaming helper.

Closes #241: The new unique_constraints feature is more powerful, but supports the exact same cases; a specific case has been added to opt out of lookups for Factory.build() and Factory.stub(). Examples are provided for Django and SQLAlchemy unique constraint declarations.

Closes #69: With the implementation of unique_constraints - and its lazy declaration resolution algorithm, non-constrained declarations will only be resolved once lookups have failed; this avoids creating orphan objects.

Closes #781: The call-time parameters are now explicitly included in the lookup algorithm; they no longer need to be kept attached to the factory class, which leaked instances.

Note: the change includes updated code, additional tests, deprecation warning and migration helpers.

rbarrois avatar Oct 11 '20 22:10 rbarrois

@francoisfreitag if you've got some time, I'd be happy to get another set of eyes on this ;)

rbarrois avatar Oct 11 '20 22:10 rbarrois

Any updates on this?

aalvrz avatar Feb 08 '21 22:02 aalvrz