Done using Django 4.2.21

I recently had to migrate a Django application to Kubernetes and in the migration process one of my Pods threw the following error message at startup:

JavaScript
RuntimeError: populate() isn't reentrant

Looking up some potential solutions, it appeared that this error message is thrown as a generic error and non specific to the underlying exception.
I found a hack which allowed me get to the real error message. Here is how.

The hack

The hack itself is very simple: replace the line that raises the error with an alternate instruction to allow Django to go on. The advice was to replace in the file python/site-packages/django/apps/registry :

Python
raise RuntimeError("populate() isn't reentrant")

with

Python
self.app_config={}

Docker version

Since I am using Kubernetes, I had to finally way to do it inside my Docker container. I could have connected directly into my Pod, but in my case the filesystems are all readonly.
So I had to add this line directly in the Dockerfile:

Dockerfile
RUN sed -i 's/raise RuntimeError("populate() isn'"'"'t reentrant")/slef.app_config= {}/g' <path_to_registry.py>

IMPORTANT: Do not forget to delete this line from your Dockerfile when you solved the error.

Result

As a result, I could get to the real error which now appeared in the logs when starting my pod (and which was related to a missing environment variable).


Leave a Reply

Your email address will not be published. Required fields are marked *