Question

djangoappengine.views.warmup does its job of loading all Django apps when GAE sends a warmup request. If GAE does not send a warmup request, either due to request spike or because warmup service is not enabled, then when does INSTALLED_APPS get imported? I see that djangoappengine.deferred.handler.application loads all INSTALLED_APPS, but djangoappengine.main.application does not.

The problem I'm having is that if there is no warmup request, then either that first loading request handler or subsequent request handler may need a nonrel-search model field which is not yet registered, because search was not imported via INSTALLED_APPS and thus autodiscover() did not yet run.

My settings MIDDLEWARE_CLASSES does have 'autoload.middleware.AutoloadMiddleware', so I would think that it could load that way without warmup, but it's not.

What is the solution to make sure everything is loaded before handling any requests?

Was it helpful?

Solution

The solution is to call search.autodiscover() in the site's urls.py, in addition to having autoload and search in INSTALLED_APPS, as well as autoload.middleware.AutoloadMiddleware in MIDDLEWARE_CLASSES.

The reason is that while djangoappengine.views.warmup and djangoappengine.deferred.handler.application load INSTALLED_APPS and result in search.autodiscover() being called, djangoappengine.main.application does not does not do that. So if your GAE instance is fired up directly by a request, then the search indexes will not be registered. Therefore, search.autodiscover() in urls.py is necessary to register those indexes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top