Skip to content
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

Add unique_constraints, a more versatile replacement for django_get_or_create and sqlalchemy_get_or_create #794

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Commits on Oct 11, 2020

  1. Expose memleak in SQLAlchemyModelFactory.

    The code responsible for `get_or_create` places a copy of the passed-in
    params on the factory class itself; which is kept after the instance has
    been created.
    
    Those fields are part of the BuildStep context, and should be fetched
    from there instead.
    
    The issue also occurs in DjangoModelFactory.
    
    See #781 for details.
    rbarrois committed Oct 11, 2020
    Configuration menu
    Copy the full SHA
    a55ec38 View commit details
    Browse the repository at this point in the history
  2. Add an optional normalization to class Meta fields

    This could be used to ensure that an entry is actually a list.
    rbarrois committed Oct 11, 2020
    Configuration menu
    Copy the full SHA
    11fe368 View commit details
    Browse the repository at this point in the history
  3. Provide support for migrating class Meta fields

    Through `def _get_renamed_options()`, a specific `FactoryOptions`
    subclass may now indicate that one of its fields should now use another
    name, and optionally another syntax.
    
    The warning message displays the new format to use when adjusting the
    option.
    rbarrois committed Oct 11, 2020
    Configuration menu
    Copy the full SHA
    5d0b77f View commit details
    Browse the repository at this point in the history
  4. Add unique_constraints and associated _lookup()

    Declare unique constraints on field values through this new `class Meta`
    option.
    
    When building a new instance, the parameters will first be resolved for
    each unique constraint, and a dedicated lookup performed; an instance
    will only be created if each lookup failed.
    
    Declarations are resolved lazily: a non-constraint SubFactory will only
    be called if each previous constraint lookup failed.
    rbarrois committed Oct 11, 2020
    Configuration menu
    Copy the full SHA
    f292b70 View commit details
    Browse the repository at this point in the history
  5. Replace *_get_or_create with unique_constraints.

    This change deprecates django_get_or_create and
    sqlalchemy_get_or_create; upgrade helpers are provided throught the
    option renaming helpers.
    
    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.
    rbarrois committed Oct 11, 2020
    Configuration menu
    Copy the full SHA
    7bfe247 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    772a067 View commit details
    Browse the repository at this point in the history
  7. Rename a StepBuilder instance to step_builder

    The variable is a StepBuilder, not a BuildStep...
    rbarrois committed Oct 11, 2020
    Configuration menu
    Copy the full SHA
    2a87857 View commit details
    Browse the repository at this point in the history