openedx / openedx/edx-django-utils

Plugin apps load at unexpected time in Django startup (no settings available)

Open
#438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
Python
Stars
28
Forks
31
Avg merge
7d 6h
Merged PRs (30d)
1

Description

Because we tell devs to call add_plugins from inside their Django settings module (DSM), and because that immediately imports the plugin app's code, the app's module initialization occurs at an unusual time for a Django app.

Specifically, any code like SOME_FEATURE = getattr(django.conf.settings, 'SOME_FEATURE', 'default') will always get 'default', rather than the configured value. In one case this caused a circuit-breaker setting not to be usable. The reason this happens is that django.conf.settings isn't usable until the entire DSM has been imported by Django during startup; if the plugin app is loaded during this time, no settings will be available. Normal apps are loaded by Django strictly after the DSM is loaded (since INSTALLED_APPS is one of the settings).

The documented workaround for this is to have plugin apps load settings only inside functions that are called at normal runtime, such as ready(). However, there may be other surprises. We may want to change our plugins utility to ensure apps are loaded by Django directly. It may be possible to do this without changing how we write settings file (perhaps by having the plugin framework itself only load the plugins in a ready() method of its own, or similar).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the add_plugins entry point and how plugin apps are imported from the Django settings module. Compare that flow with Django's normal app loading and the documented workaround of reading settings in ready(). Define and test a loading approach that makes settings available before plugin app module initialization, while preserving plugin configuration usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.