paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
390 stars 67 forks source link

Can we change persist_dependencies to False by default on N? #52

Closed wesleykendall closed 4 years ago

wesleykendall commented 9 years ago

According to https://github.com/paulocheque/django-dynamic-fixture/blob/master/django_dynamic_fixture/__init__.py#L71 and the docs, persist_dependencies is True by default for the N function. Almost 100% of time in our code we have to type persist_dependencies=False, and it's cumbersome to have to manually review code and ensure people aren't accidentally hitting the DB when they instantiate in-memory models.

My question - can this default behavior be changed? If it's too backwards breaking, can I add an M function that is N with persist_dependencies=False?

micahhausler commented 9 years ago

+1

paulocheque commented 9 years ago

Change the default value I dont think it is a good idea because it may break every test for every people using the tool after upgrading the library.

I believe it is a good idea to have a method like this, but we have to find a good name for it. Why do you think in M?

In the mean time, I believe you can create a wrapper like that:

def something(model, shelve=False, n=1, persist_dependencies=False, **kwargs):
    N(model, shelve=shelve, n=n, persist_dependencies=persist_dependencies, **kwargs)

N = something
micahhausler commented 9 years ago

@paulocheque what do you think about this?

# global_settings.py
DDF_N_PERSIST_DEPENDENCIES = get_boolean_config('DDF_N_PERSIST_DEPENDENCIES', default=True)

# django_dynamic_fixture/__init__.py
def new(model, shelve=False, n=1, persist_dependencies=DDF_N_PERSIST_DEPENDENCIES, **kwargs):
paulocheque commented 9 years ago

Very cool! Could you make a PR?

wesleykendall commented 9 years ago

@paulocheque I'll do a PR/tests/docs if you are fine with that implementation. This will help us tremendously!

paulocheque commented 9 years ago

Amazing! I will merge and generate a release for it! best!

paulocheque commented 4 years ago

Well, I changed the default value for the next DDF version 3, which will have some big changes and incompatibilities with older versions.

https://github.com/paulocheque/django-dynamic-fixture/pull/108

Thanks @wesleykendall @micahhausler

wesleykendall commented 4 years ago

@paulocheque thanks so much for this change! Loving version 3!