#24523: django.apps.registry.populate() does not handle failures in app_config.ready() -------------------------------+-------------------- Reporter: kalium99 | Owner: nobody Type: Bug | Status: new Component: Uncategorized | Version: 1.7 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- Hi,
I'm using DJango 1.7, Apache 2.2 + mod_wsgi. Here is a snippet of the error that I see on the server side logs: [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] mod_wsgi (pid=27852): Target WSGI script '/home/test/prod_wsgi.py' cannot be loaded as Python module. [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] mod_wsgi (pid=27852): Exception occurred processing WSGI script '/home/test/prod_wsgi.py'. [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] Traceback (most recent call last): [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/test/example/prod_wsgi.py", line 24, in <module> [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] application = get_wsgi_application() [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] django.setup() [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/__init__.py", line 21, in setup [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] apps.populate(settings.INSTALLED_APPS) [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] app_config.ready() [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/contrib/admin/apps.py", line 22, in ready [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] self.module.autodiscover() [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site- packages/django/contrib/admin/__init__.py", line 23, in autodiscover [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] autodiscover_modules('admin', register_to=site) [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site- packages/django/utils/module_loading.py", line 74, in autodiscover_modules [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] import_module('%s.%s' % (app_config.name, module_to_search)) [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] __import__(name) [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/test/apps/partners/admin.py", line 5, in <module> [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] from apps.partners.forms import url_status_change [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/test/apps/partners/forms.py", line 42, in <module> [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] class PartnerSelection(forms.Form): [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/test/apps/partners/forms.py", line 44, in PartnerSelection [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] (p.id, p.company_name) for p in Partner.objects.all()]) [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/db/models/query.py", line 141, in __iter__ [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] self._fetch_all() ... [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__ [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] super(Connection, self).__init__(*args, **kwargs2) [Sun Mar 22 23:47:26 2015] [error] [client 127.0.0.1] OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)") So obviously, can't connect the the database. This is fine and expected (apart from the DB being down part...). The problem is that this leaves the 'App' object in an erroneous state. The 'app_config' var has been populated, but the local 'ready' variable has not been set to True. This means that even after the DB issue has been cleared, subsequent calls to app.populate() will fail for no obvious reason (notice the PID is the same as the previous DB error). [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] mod_wsgi (pid=27852): Target WSGI script '/home/test/example/prod_wsgi.py' cannot be loaded as Python module., referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] mod_wsgi (pid=27852): Exception occurred processing WSGI script '/home/test/example/prod_wsgi.py'., referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] Traceback (most recent call last):, referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] File "/home/test/example/prod_wsgi.py", line 24, in <module>, referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] application = get_wsgi_application(), referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application, referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] django.setup(), referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/__init__.py", line 21, in setup, referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] apps.populate(settings.INSTALLED_APPS), referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] File "/home/testenv/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate, referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] raise RuntimeError("populate() isn't reentrant"), referer: http://www.example.tv/ [Sun Mar 22 23:57:17 2015] [error] [client 127.0.0.1] RuntimeError: populate() isn't reentrant, referer: http://www.example.tv/ I'm no Django expert, but it seems the way set and test 'app_config' and 'ready', are a bit off. I'm guessing that it is just simpler to not bother testing app_config for truth. If we are not 'ready', then just set app_config to the empty list and re-populate it, as if ready is not True, then we probably can't make too many assumptions about anything else (i.e that app_config has even bee populated correctly). It's highly possible that there is a gap in my knowledge and there are better solutions to this. -- Ticket URL: <https://code.djangoproject.com/ticket/24523> 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/051.5798a84eeb4984e02996e2fcfa31d9a7%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.