#22280: "Conflicting models in application" RuntimeError for same model with different paths ------------------------------+-------------------- Reporter: blueyed | Owner: nobody Type: Bug | Status: new Component: Core (Other) | Version: master Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------+-------------------- When I run tests using `manage.py test`, the test file `project/app/tests.py` is used/imported with `__name__ = "project.project.app.test"`.
When using a relative import in tests.py then, the model appears to get registered as `project.project.app.model`. After the database for the tests is being setup, I get the following error: > RuntimeError: Conflicting 'model' models in application 'app': <class 'app.models.Model'> and <class 'project.project.app.models.Model'>. It refers to the same Model, but with different class paths. This is triggered by / caused when using an relative import from the tests.py file: `from .models import Model`. I am running manage.py from the first "project" directory. `sys.path` contains the directory `.../project/project` and not the directory where `project.project.app` would be rooted. With Django 1.6 the `__name__` of tests.py during the import is the same, but there's no error, since there is no apploader that verifies uniqueness using the labels/names. I could not reproduce it with a simple new project/app in Django 1.7. {{{ ERROR: project.project.app.tests (unittest.loader.ModuleImportFailure) ---------------------------------------------------------------------- ImportError: Failed to import test module: project.project.app.tests Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name __import__(name) File "…/project/app/tests.py", line 23, in <module> from .views import HomePageView File "…/project/app/views.py", line 6, in <module> from .models import Movie, Collection File "…/project/app/models.py", line 51, in <module> class Person(models.Model): File "…/django-master/django/db/models/base.py", line 299, in __new__ new_class._meta.apps.register_model(new_class._meta.app_label, new_class) File "…/django-master/django/apps/registry.py", line 201, in register_model (model_name, app_label, app_models[model_name], model)) RuntimeError: Conflicting 'person' models in application 'app': <class 'app.models.Person'> and <class 'project.project.app.models.Person'>. }}} -- Ticket URL: <https://code.djangoproject.com/ticket/22280> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.a151cf6f37156f0db4d5e1ba9a639785%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.