Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add warning about loading Django settings in plugin apps #439

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ Using edx-cookiecutter
^^^^^^^^^^^^^^^^^^^^^^
The simplest way to create a new plugin for edx-platform is to use the edx-cookiecutter tool. After creating a new repository, follow the instructions for cookiecutter-django-app. This will allow you to skip step 1 below, as the cookie cutter will create a skeleton App Config for you.

Warning
^^^^^^^

.. warning:: Plugin apps do not load at the usual point in Django's startup sequence. This section describes some known adverse effects of this.

Django settings are not available during module initialization in a plugin app, as the app's code is first imported before the settings module has been imported. While the following code will usually do the right thing in a Django app, it will always get the *default* value in a plugin app:

.. code:: python

from django.conf import settings

# Always returns None (when run at top level)
SOME_FEATURE = getattr(settings, 'SOME_FEATURE', None)

Instead, this initialization should be moved to the ``ready()`` method or similar.

(See `<https://github.com/openedx/edx-django-utils/issues/438>`__ for possible ways to remove this stumbling block in the future.)

Manual setup
^^^^^^^^^^^^

Expand Down