Skip to content

Commit

Permalink
Merge pull request #142 from jayvdb/dj32-InvalidModelError
Browse files Browse the repository at this point in the history
Catch Django 3.2 TypeError instantiating abstracts
  • Loading branch information
paulocheque committed Sep 24, 2021
2 parents 24fc2c6 + a18e7a8 commit 3ea4af7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion django_dynamic_fixture/ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ def new(self, model_class, ddf_lesson=None, persist_dependencies=True, **kwargs)
if self.debug_mode:
LOGGER.debug('>>> [%s] Generating instance.' % get_unique_model_name(model_class))
configuration = self._configure_params(model_class, ddf_lesson, **kwargs)
instance = model_class()
try:
instance = model_class()
except TypeError:
raise InvalidModelError(get_unique_model_name(model_class))
if not is_model_class(instance):
raise InvalidModelError(get_unique_model_name(model_class))

Expand Down
1 change: 1 addition & 0 deletions django_dynamic_fixture/tests/test_ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def test_new_create_with_min_depth_2(self):


class NewDealWithInheritanceTest(DDFTestCase):
@pytest.mark.skipif(django.VERSION > (3, 2), reason="Not supported on Django 3.2+")
def test_new_must_not_raise_an_error_if_model_is_abstract(self):
self.ddf.new(ModelAbstract) # it does not raise an exceptions

Expand Down

0 comments on commit 3ea4af7

Please sign in to comment.