Order of INSTALLED_APPS

1,548 views
Skip to first unread message

Stefano Crosta

unread,
Aug 12, 2013, 7:34:38 AM8/12/13
to django-d...@googlegroups.com
Hello!


There is one situation where the order of INSTALLED_APPS really matters - which is template override.


Though not officially documented (?) I've found references in the mailing list to the fact that APPS coming first in the INSTALLED_APPS will have priority - their templates will be loaded effectivily overriding/shadowing lower priority app ones.

Now, if this is "officially" confirmed in my opinion it would require:

  1. use a list, not a set, as a default for INSTALLED_APPS. In Python sets are unordered as you surely now better than me
  2. be more explicit in the documentation
If it's not, well... maybe another mechanism should be implemented. For very specific cases I've been using https://pypi.python.org/pypi/django-apptemplates/  which syntax looks very clean and clear to me. I'm not sure if there are other drawbacks or if this would be worth including natively into django rather then leaving it as an (abandoned) external app...

Thanks!

Stefano

Aymeric Augustin

unread,
Aug 12, 2013, 8:59:13 AM8/12/13
to django-d...@googlegroups.com
2013/8/12 Stefano Crosta <stefano...@gmail.com>

There is one situation where the order of INSTALLED_APPS really matters - which is template override.

There are at least two other similar cases: translations and static files.
 
Though not officially documented (?) I've found references in the mailing list to the fact that APPS coming first in the INSTALLED_APPS will have priority - their templates will be loaded effectivily overriding/shadowing lower priority app ones.

Yes, we should standardize and document that.

On a related note, some lookups depend on the INSTALLED_APPS settings and others depend on the list of applications registered in the AppCache. The latter may be a superset of the former. We should give some thought to this problem before committing to a given discovery behavior.

Eventually, Django should probably raise an error when the AppCache loads a model from an application than isn't in INSTALLED_APPS. But there may be uses cases for this eg. dynamically generated models. Enough said, I'm stopping this digression here :)
 
Now, if this is "officially" confirmed in my opinion it would require:
  1. use a list, not a set, as a default for INSTALLED_APPS. In Python sets are unordered as you surely now better than me
The default generated settings file defines INSTALLED_APPS a tuple, not a set.

We could change it to a list, however, that will introduce inconsistencies with other settings where the default value is a tuple and can't be changed without introducing backwards incompatibilities.
  1. be more explicit in the documentation
Yes!

--
Aymeric.

Ramiro Morales

unread,
Aug 12, 2013, 9:41:15 AM8/12/13
to django-d...@googlegroups.com
On Mon, Aug 12, 2013 at 9:59 AM, Aymeric Augustin
<aymeric....@polytechnique.org> wrote:
> 2013/8/12 Stefano Crosta <stefano...@gmail.com>
>
>> There is one situation where the order of INSTALLED_APPS really matters -
>> which is template override.
>
>
> There are at least two other similar cases: translations and static files.
>
>>
>> Though not officially documented (?) I've found references in the mailing
>> list to the fact that APPS coming first in the INSTALLED_APPS will have
>> priority - their templates will be loaded effectivily overriding/shadowing
>> lower priority app ones.
>
>
> Yes, we should standardize and document that.

For translations, we have such documentation already:

https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-translations

--
Ramiro Morales
@ramiromorales

Florian Apolloner

unread,
Aug 12, 2013, 2:29:49 PM8/12/13
to django-d...@googlegroups.com
On Monday, August 12, 2013 3:41:15 PM UTC+2, Ramiro Morales wrote:
For translations, we have such documentation already:

https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-translations

Stefano Crosta

unread,
Aug 13, 2013, 6:09:45 AM8/13/13
to django-d...@googlegroups.com
Aymeric, Ramiro, Florian,

thanks a lot for your answers!

Indeed there is some (slightly hidden :D ) documentation! 
And it has improved since 1.5, I now see! - I remembered reading something before, but I couldn't find them anymore when I wrote yesterday's message.

My proposal would then be to simply add another box to the https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps to say "order matters" once more and link the other two pages for translations and templates.
*if you think this would* help I could do it as well as a ticket. To save everybody's time no answer will mean it's not worth it!

(PS. Also please fully disregard my momentary lapse of reason concerning `sets` in the settings - I don't know what got into me)

thanks&best,
Stefano

Aymeric Augustin

unread,
Aug 13, 2013, 6:20:48 AM8/13/13
to django-d...@googlegroups.com
2013/8/13 Stefano Crosta <stefano...@gmail.com>

My proposal would then be to simply add another box to the https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps to say "order matters" once more and link the other two pages for translations and templates.
*if you think this would* help I could do it as well as a ticket. To save everybody's time no answer will mean it's not worth it!

Yes, please file one, and include a link to this discussion.

--
Aymeric.

Stefano Crosta

unread,
Aug 14, 2013, 5:26:47 AM8/14/13
to django-d...@googlegroups.com

Kevin Christopher Henry

unread,
Sep 1, 2013, 4:31:49 PM9/1/13
to django-d...@googlegroups.com
Sorry to be late to this thread, I just came across it.

There's another place where the order of INSTALLED_APPS matters: management commands. Management commands associated with apps that come later in INSTALLED_APPS will replace those with the same name that are listed earlier. I can't find this documented anywhere, but a look at the code confirms it. South, for example, takes advantage of this to override the syncdb command (and hints at the ordering issue when the documentation says: "add 'south' to the end of INSTALLED_APPS").

So a documentation update should probably note this specifically in the management documentation, as well as mentioning it in the box for INSTALLED_APPS. (I also think static files should also be mentioned in the box, since as Aymeric points out that is another area dependent on the order of apps.)

One thing that's unfortunate is that the semantics of ordering for management commands is opposite that of the other cases. For templates, static files, and translations, listing an app first gives it precedence, whereas with management commands it's listing it last. Ideally this would be changed so that management commands were consistent with the other cases, but that would create serious backwards compatibility issues. Like, breaking everyone's South installation. :-O

Cheers,
Kevin

Marc Tamlyn

unread,
Sep 1, 2013, 6:04:03 PM9/1/13
to django-d...@googlegroups.com

I don't think it would break South installations as custom app commands will always override builtins. Could you open a ticket for that? The inconsistency is problematic. Obviously it would be backwards incompatible, but we need to gauge the size of the impact.

Marc

--
You received this message because you are subscribed to the Google Groups "Django developers" 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.
For more options, visit https://groups.google.com/groups/opt_out.
Message has been deleted

VernonCole

unread,
Sep 2, 2013, 5:34:03 AM9/2/13
to django-d...@googlegroups.com
It also affects _how_ South works, not just _whether_ it works.  Only this week I had to install a patch for the formhub package which consisted of re-ordering INSTALLED_APPS so that tables were built in the correct order on PostgreSQL installations.

Shai Berger

unread,
Sep 2, 2013, 6:22:43 AM9/2/13
to django-d...@googlegroups.com
On Monday 02 September 2013 12:34:03 VernonCole wrote:
> It also affects _how_ South works, not just _whether_ it works. Only this
> week I had to install a patch for the formhub package which consisted of
> re-ordering INSTALLED_APPS so that tables were built in the correct order
> on PostgreSQL installations.
>
This is getting off-topic for this list -- but South has a concept of
dependencies between migrations, which is the right way to get migrations in
the right order. You shouldn't depend on INSTALLED_APPS order for that.

Unless I'm missing something, in which case, let's take it to the South list.

Shai.

German Larrain

unread,
Sep 9, 2013, 6:32:48 PM9/9/13
to django-d...@googlegroups.com
Hi guys

A related question: What about repeated entries of apps in INSTALLED_APPS? I remember seeing this once and, if I recall correctly, no errors were raised. I guess ImproperlyConfigured would be a suitable exception.

Germán

Tim Graham

unread,
Sep 10, 2013, 8:02:14 AM9/10/13
to django-d...@googlegroups.com
Yes, here's the ticket to add validation for INSTALLED_APPS: https://code.djangoproject.com/ticket/12288
Reply all
Reply to author
Forward
0 new messages