Opened 6 years ago

Closed 6 years ago

Last modified 14 months ago

#26214 closed Cleanup/optimization (wontfix)

Better error message for RuntimeError: populate() isn't reentrant

Reported by: Thomas Güttler Owned by: nobody
Component: Core (Other) Version: 1.9
Severity: Normal Keywords:
Cc: Aymeric Augustin Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Thomas Güttler)

We were hit by an exception like this in production environment

Traceback (most recent call last):
  File "foobar-fm/foobar_fm/apache/", line 4, in <module>
    application = wsgi.get_handler()
  File "djangotools/djangotools/utils/", line 54, in get_handler
    return get_wsgi_application()
  File "lib/python2.7/site-packages/django/core/", line 14, in get_wsgi_application
  File "lib/python2.7/site-packages/django/", line 18, in setup
  File "lib/python2.7/site-packages/django/apps/", line 78, in populate
    raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant

To debug this, I am missing an very important part:

The Stacktrace of the other one trying to load the config

Here is the code part

            # app_config should be pristine, otherwise the code below won't
            # guarantee that the order matches the order in INSTALLED_APPS.
            if self.app_configs:
                raise RuntimeError("populate() isn't reentrant")

My idea: the first one, who passes above check stores its current stracktrace to a variable.

The if the second fails, and RuntimeError("populate() isn't reentrant") gets executed, the exception can show the stacktrace of the first run.

With this you can debug it. Otherwise you are lost.

What do you think?

Change History (6)

comment:1 Changed 6 years ago by Thomas Güttler

Description: modified (diff)

comment:2 Changed 6 years ago by Tim Graham

Cc: Aymeric Augustin added
Component: Error reportingCore (Other)
Owner: set to nobody
Type: UncategorizedCleanup/optimization

I'm not sure. Aymeric, what's your opinion?

comment:3 Changed 6 years ago by Aymeric Augustin

I understand the reasoning behind this suggestion, but in my experience, trying to be smart with error handling often backfires, and my gut feeling is that this is too magical.

Besides Python 3's exception chaining solves the problem entirely... Let's say that my motivation for doing something is non-existent, given that I don't plan to ever use Python 2 again.

comment:4 Changed 6 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

The rationale makes sense to me.

comment:5 Changed 6 years ago by Thomas Güttler

Python 3's exception chaining solves the problem entirely.

I only used Python2 up to now. I guess it is time to upgrade.

Thank you for your feedback.

comment:6 Changed 14 months ago by Thomas Güttler

5 years later, running Python 3.8 I come across the same error again. On the Python command line it works, there I see the real error: ModuleNotFoundError: No module named 'psycopg2'

But if I run this via PyCharm "execute file". I get the meaningless error message.

Here is an answer to see the real error message, if you don't see it: (replace the exection in with self.app_configs = {})

Note: See TracTickets for help on using tickets.
Back to Top