Hi,
On Wednesday, January 13, 2016 at 12:54:59 AM UTC+2, John Bazik wrote:
I have never used Django-CMS, but according to your description, it (or its plugins) is doing what
applications should avoid doing since Django 1.7 and the app-loading refactor. Registrations which
involve interactions with applications -- and loading templates falls under this definition -- should
happen only in an app's AppConfig.ready(), after all the models are already loaded.
Loading templates involves a trivial interaction with apps in the sense that apps' template directories
are used as template sources; but it can be deeper, because, as in your example, 3rd-party template
loaders may use models for loading them. It can be the site object as here, it can even be the
templates themselves stored in the database.
The question of whether Django should be calling apps.populate() to unpickle a model (instance) will
be better discussed on django-developers, but I think that with well-behaved apps it is harmless.
HTH,
Shai.
-- On Wednesday, January 13, 2016 at 12:54:59 AM UTC+2, John Bazik wrote:
Breaking it down:
- Django.setup wants to load all apps, and calls apps.populate
- Django-cms plugins register themselves at load time
- Django-cms plugin registration involves loading templates
I have never used Django-CMS, but according to your description, it (or its plugins) is doing what
applications should avoid doing since Django 1.7 and the app-loading refactor. Registrations which
involve interactions with applications -- and loading templates falls under this definition -- should
happen only in an app's AppConfig.ready(), after all the models are already loaded.
- Django-multisite provides a template loader (for per-site templates)
- Django-multisite also monkey-patches Sites' cache (normally a dict) with a wrapper around a django cache
- The django-multisite template loader fetches the current site from cache when loading template
Loading templates involves a trivial interaction with apps in the sense that apps' template directories
are used as template sources; but it can be deeper, because, as in your example, 3rd-party template
loaders may use models for loading them. It can be the site object as here, it can even be the
templates themselves stored in the database.
I could break the cycle any number of places, but it seems to me that all the apps are doing reasonable things (monkey patching aside), and django shouldn't be calling apps.populate to unpickle a model. Perhaps that is unavoidable?
- Django's LocMemCache backend fetches a pickled model from cache
- It is implicitly unpickled by django.db.models.base.Model which calls model_unpickle
- model_unpickle tests if apps.ready is true and if not, calls apps.populate
The question of whether Django should be calling apps.populate() to unpickle a model (instance) will
be better discussed on django-developers, but I think that with well-behaved apps it is harmless.
HTH,
Shai.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0ac3f5de-acdd-4acb-8e6f-606413f6d40a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment