paulocheque / django-dynamic-fixture

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

Is it required to set ForeignKey relationship explicitly for G? #120

Closed ghost closed 4 years ago

ghost commented 4 years ago

Thank for contributors of this awesome project. Everything works fine before. However, when I upgrade to 3.x, I got IntegrityError when run tests that passed before.

My model like this:

class Category(TimeStampedModel):
    creator = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('creator'), on_delete=models.CASCADE)

The test code:

def setUp(self):
    self.category = G(Category)

Error reported by pytest:

self = <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x00000270FF45C558>
query = 'INSERT INTO "blog_category" ("created", "modified", "name", "title", "slug", "description", "cover", "cover_caption", "creator_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'
params = ['2020-01-11 06:32:56.622249', '2020-01-11 06:32:56.622249', 'cate1', '5', '5', '5', ...]

    def execute(self, query, params=None):
        if params is None:
            return Database.Cursor.execute(self, query)
        query = self.convert_query(query)
>       return Database.Cursor.execute(self, query, params)
E       django_dynamic_fixture.ddf.BadDataError: ('blog.models.Category', IntegrityError('NOT NULL constraint failed: blog_category.creator_id'))

How could I fix this?

paulocheque commented 4 years ago

I will take a look into this, fix and create a new release! Thanks for reporting!

paulocheque commented 4 years ago

In the meantime, you can put in your settings.py: DDF_NUMBER_OF_LAPS = 1

ghost commented 4 years ago

Yes! That solve part of the issue. It seems a lot of default behevior such as fill_nullable_fields also does not active by default. 3.0 introduce some incompatible features but seems can not find in the docs.

saadmk11 commented 4 years ago

I can confirm this issue. I don't think this was the case on version 2.0.0.

jklaiho commented 4 years ago

Ran into this today also, and I confirmed that this did not happen in 2.0.0.

paulocheque commented 4 years ago

This PR should fix this issue: https://github.com/paulocheque/django-dynamic-fixture/pull/125

paulocheque commented 4 years ago

Please, try the version 3.0.3. Thanks again for reporting.