manage.py test and uninstalled apps

149 views
Skip to first unread message

Claude Paroz

unread,
Nov 18, 2015, 3:04:34 PM11/18/15
to Django developers (Contributions to Django itself)
Hello,

I have a Django project with different apps and settings. Let's say settings A have A in INSTALLED_APPS but not B, and settings B have B in INSTALLED_APPS but not A. Note also that I cannot have both apps installed, for some reason.
In that configuration and from Django 1.9, ./manage.py test will always fail with the message :
    RuntimeError: Model class <myapp.models.MyModel> doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded.

Do we admit that for such type of projects, you always have to specify your app labels starting from Django 1.9?
Or did I miss some hidden trick to avoid that?

Claude


Aymeric Augustin

unread,
Nov 18, 2015, 3:29:08 PM11/18/15
to django-d...@googlegroups.com
Hello Claude,

Generally speaking, you cannot safely use a model that isn't defined in an application that is in INSTALLED_APPS. Django raises a warning when you import such a model.

This restriction prevents situations where relations between models aren't set up correctly. There’s a string of such bugs in Trac. I discussed this in my DjangoCon Europe 2014 talk.

Best regards,

-- 
Aymeric.



--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/b7d021c5-bc44-48e6-8441-b57a40758c53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Claude Paroz

unread,
Nov 19, 2015, 2:27:20 AM11/19/15
to Django developers (Contributions to Django itself)
Hello Aymeric,

To be clear, I don't contest in any way that design choice. I understand and approve it.
I'm just pointing to this unwanted side-effect, wondering if anyone has ideas how to circumvent it, as I think it's a legitimate use case.
I'm also aware that we have not much control over test discovery and importing process.

The workaround for me will probably to write a custom test management command to define test labels dynamically based on current settings.

Claude

Aymeric Augustin

unread,
Nov 19, 2015, 6:38:21 AM11/19/15
to django-d...@googlegroups.com
2015-11-19 8:27 GMT+01:00 Claude Paroz <cla...@2xlibre.net>:
To be clear, I don't contest in any way that design choice. I understand and approve it.
I'm just pointing to this unwanted side-effect, wondering if anyone has ideas how to circumvent it, as I think it's a legitimate use case.

Ah, I misunderstood "to specify your app labels" as "to specify your app labels on your models' Meta classes" while you meant "to specify your app labels on the command line when running tests".

Since the test discovery will try to import everything and problems appear when importing models, I'm afraid there isn't a good solution here.
 
--
Aymeric.
Reply all
Reply to author
Forward
0 new messages