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

Nullable ForeignKey is still None with explicit fill_nullable_fields in G #148

Closed hexponent closed 2 years ago

hexponent commented 2 years ago

After upgrading from 2.0.0 to 3.0.0 (and it is still valid for 3.1.2) I face the following problem when running tests - even though I specify fill_nullable_fields=True in G, I get None for the corresponding ForeignKey field. I also tried to set DDF_FILL_NULLABLE_FIELDS=True in my settings, but it didn't help either.

My model:

class Plan(models.Model):
    permissions = models.ForeignKey(Permissions, null=True, on_delete=models.SET_NULL)

My test:

def test_ddf(self):
    self.assertIsNotNone(
        G(Plan, fill_nullable_fields=True).permissions
    )

And error is AssertionError: unexpectedly None

hexponent commented 2 years ago

Specifying DDF_FK_MIN_DEPTH in settings solved problem. In this case 1 is enough, and for more advanced logic 5 helped.