paulocheque / django-dynamic-fixture

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

Fix fixture generation for polymorphic models (including MTI subclasses). #59

Closed mrmachine closed 4 years ago

mrmachine commented 9 years ago

If the model is a PolymorphicModel then it has a polymorphic_ctype field which shouldn't be touched. Changing it will cause the model not to be found by its own querysets.

MTI subclasses have a OneToOneField as their primary key, which should also not be touched.

landscape-bot commented 9 years ago

Code Health Repository health increased by 2% when pulling 428a933 on ixc:ixc/fix-for-polymorphic-models into f5f7207 on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.27%) to 79.6% when pulling 428a933a27fce210a5ace5c4bf76aea42c799ea7 on ixc:ixc/fix-for-polymorphic-models into f5f72077eef6fcdc2113e332561fe5118aa4c85f on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.27%) to 79.6% when pulling 428a933a27fce210a5ace5c4bf76aea42c799ea7 on ixc:ixc/fix-for-polymorphic-models into f5f72077eef6fcdc2113e332561fe5118aa4c85f on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.27%) to 79.6% when pulling 428a933a27fce210a5ace5c4bf76aea42c799ea7 on ixc:ixc/fix-for-polymorphic-models into f5f72077eef6fcdc2113e332561fe5118aa4c85f on paulocheque:master.

mrmachine commented 9 years ago

The failing tests are Django 1.2 and 1.3, which need an earlier version of django-polymorphic. I started fixing the tests, but eventually submitted #60 instead which simplifies the tox.ini using generative envlist and conditional factors, drops Django 1.2 and 1.3 which are no longer supported, and adds some versions of Python that are supported (according to release notes) of current Django releases.

If Django 1.2 and 1.3 support is still desired, just move the django-polymorphic from requirements.txt and into tox.ini with conditional factors:

envlist =
    django{12,13}-py{26,27},
    django14-py{26,27},
    django16-py{26,27,32,33},
    django17-py{27,32,33,34}

deps =
    -r{toxinidir}/requirements.txt
    django12: django>=1.2,<1.3
    django13: django>=1.3,<1.4
    django14: django>=1.4,<1.5
    django16: django>=1.6,<1.7
    django17: django>=1.7,<1.8
    django{12,13}: django_polymorphic<0.4.2
    django{14,16,17}: django_polymorphic>=0.4.2
landscape-bot commented 9 years ago

Code Health Repository health increased by 2% when pulling 1b15db7 on ixc:ixc/fix-for-polymorphic-models into f5f7207 on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.27%) to 79.6% when pulling 1b15db782b8cc4e4213c28b09279a6618569ea4f on ixc:ixc/fix-for-polymorphic-models into f5f72077eef6fcdc2113e332561fe5118aa4c85f on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.27%) to 79.6% when pulling 1b15db782b8cc4e4213c28b09279a6618569ea4f on ixc:ixc/fix-for-polymorphic-models into f5f72077eef6fcdc2113e332561fe5118aa4c85f on paulocheque:master.

landscape-bot commented 9 years ago

Code Health Code quality remained the same when pulling 605e7fa on ixc:ixc/fix-for-polymorphic-models into 3cffded on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.16%) to 76.72% when pulling 605e7fa01153bc6aeb88c235010a1ef799925f72 on ixc:ixc/fix-for-polymorphic-models into 3cffded3740e7cc811bfa4c27677c38dba042732 on paulocheque:master.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.16%) to 76.72% when pulling 605e7fa01153bc6aeb88c235010a1ef799925f72 on ixc:ixc/fix-for-polymorphic-models into 3cffded3740e7cc811bfa4c27677c38dba042732 on paulocheque:master.

mrmachine commented 9 years ago

@paulocheque any feedback on this?

paulocheque commented 9 years ago

@mrmachine I dont like the idea to include a dependency directly in the core of the library. Do you think it is possible to implement this flexibility in an abstract way?

Do you think it is possible to fix this using Custom Field Fixture? http://ddf.codeart.io/en/latest/data_fixtures.html#custom-field-fixture

If it is possible, maybe we can create a common_datafixture.py to include fixtures/plugins for common libraries. In this way, the dependency will not be in the core of the DDF.

What do you think?

stianpr commented 8 years ago

@mrmachine Any progress on this? Would be nice to get a release with support for django-polymorphic.

mrmachine commented 8 years ago

@stianpr I've just been using a fork with this fixed as above.

@paulocheque I really don't know how or if polymorphic support could be fixed with a custom field fixture. django-polymorphic is not using any custom model fields. It has an FK to Django's ContentType model, and it is using Django's multi-table-inheritance for the parent and child models.

Perhaps other models besides polymorphic models would also have fields that should not be touched by DDF (e.g. the _ptr field on MTI child models), and so perhaps a generic way to tell DDF which fields to ignore for which types of models could resolve this without introducing a dependency on django-polymorphic.

Or perhaps you could elaborate on how you think a custom field fixture might help?

stianpr commented 8 years ago

@mrmachine could #67 solve this issue? I haven't really tested it but it sounds like thats the issue you address in the summary?

paulocheque commented 4 years ago

Closing in favor of https://github.com/paulocheque/django-dynamic-fixture/pull/112