I recently made the unpleasant discovery that a Django setting I had added to a plugin app as a feature switch did not actually work when I needed to disable the feature in a hurry.
Here’s the sort of code that does the wrong thing in a plugin app if it’s run at module import time (e.g. written at the module top level):
from django.conf import settings
SOME_FEATURE = getattr(settings, 'SOME_FEATURE', None)
In a normal Django app that’s loaded via INSTALLED_APPS
, SOME_FEATURE
will receive the configured value; in a plugin app, it will receive None
.
It turns out this is because the plugin app is imported while the settings are still loading, which means none of the settings are available yet. The workaround is to move that initialization to the ready()
method or similar.
I’ve added a warning to the docs for now, but also see https://github.com/openedx/edx-django-utils/issues/438 for possible ways to remove this stumbling block in the future.