Skip to content

Commit

Permalink
Merge pull request #90 from Viralize/fix_88
Browse files Browse the repository at this point in the history
FIX #88: Use DDF_IGNORE_FIELDS globally for all new instances
  • Loading branch information
paulocheque committed Aug 7, 2017
2 parents 3f0c879 + f231d94 commit 1a93ba5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion django_dynamic_fixture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def fixture(**kwargs):
print_errors=kwargs.pop('print_errors', True),
debug_mode=kwargs.pop('debug_mode', DDF_DEBUG_MODE),
**kwargs)
f.ignore_fields.extend(DDF_IGNORE_FIELDS)
return f


Expand Down
11 changes: 9 additions & 2 deletions django_dynamic_fixture/ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ def __init__(self, data_fixture, fill_nullable_fields=True, ignore_fields=[], nu
:print_errors: flag to determine if the model data must be printed to console on errors. For some scripts is interesting to disable it.
:model_path: internal variable used to control the cycles of dependencies.
"""
from django_dynamic_fixture.global_settings import DDF_IGNORE_FIELDS

# custom config of fixtures
self.data_fixture = data_fixture
self.fill_nullable_fields = fill_nullable_fields
self.ignore_fields = ignore_fields
# extend ignore_fields with globally declared ignore_fields
self.ignore_fields.extend(DDF_IGNORE_FIELDS)
self.number_of_laps = number_of_laps
self.use_library = use_library
# other ddfs configs
Expand Down Expand Up @@ -387,9 +391,12 @@ def set_data_for_a_field(self, model_class, __instance, __field, persist_depende
LOGGER.debug('%s.%s = %s' % (get_unique_model_name(model_class), __field.name, data))
try:
setattr(__instance, __field.name, data) # Model.field = data
except ValueError as e:
except (ValueError, AttributeError) as e:
if is_relationship_field(__field):
setattr(__instance, "%s_id" % __field.name, data) # Model.field = data
# Handle AttributeError for compatibility with django-polymorphic
# https://github.com/paulocheque/django-dynamic-fixture/issues/88
field_value = data.id if isinstance(e, AttributeError) else data
setattr(__instance, "%s_id" % __field.name, field_value) # Model.field = data
else:
six.reraise(*sys.exc_info())
self.fields_processed.append(__field.name)
Expand Down

0 comments on commit 1a93ba5

Please sign in to comment.