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

Broken Postgres JSONField #122

Closed andrkhr closed 4 years ago

andrkhr commented 4 years ago

Hello! In version 3 it broke Postgres JSONField :(

ddf 3.0.2

# model.py
class Record(models.Model):
    data = JSONField(default=dict)

# test.py
N(Record, data={'a': 1})

getting an error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/venv/staff.3.8.1/lib/python3.8/site-packages/django_dynamic_fixture/ddf.py in set_data_for_a_field(self, model_class, _DynamicFixture__instance, _DynamicFixture__field, persist_dependencies, **kwargs)
    382             try:
--> 383                 data = self._process_field_with_customized_fixture(__instance, __field, config, persist_dependencies)
    384             except PendingField:

~/venv/staff.3.8.1/lib/python3.8/site-packages/django_dynamic_fixture/ddf.py in _process_field_with_customized_fixture(self, instance, field, fixture, persist_dependencies)
    320         if isinstance(fixture, DynamicFixture): # DynamicFixture (F)
--> 321             data = self._get_data_from_custom_dynamic_fixture(field, fixture, persist_dependencies)
    322         elif isinstance(fixture, Copier): # Copier (C)

~/venv/staff.3.8.1/lib/python3.8/site-packages/django_dynamic_fixture/ddf.py in _get_data_from_custom_dynamic_fixture(self, field, fixture, persist_dependencies)
    282         "return data of a Dynamic Fixture: field=F(...)"
--> 283         next_model = get_related_model(field)
    284         if persist_dependencies:

~/venv/staff.3.8.1/lib/python3.8/site-packages/django_dynamic_fixture/django_helper.py in get_related_model(field)
    148 def get_related_model(field):
--> 149     return field.remote_field.model if hasattr(field, 'remote_field') else field.rel.to
    150 

AttributeError: 'NoneType' object has no attribute 'model'
vishes-shell commented 4 years ago

It does not resolve the problem, but as a workaround providing value after fixture initialization solves issue.

record = N(Record)
record.data = {'a': 1}
paulocheque commented 4 years ago

Thanks for reporting, this PR should fix this issue: https://github.com/paulocheque/django-dynamic-fixture/pull/126

paulocheque commented 4 years ago

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