Description
When running the constance management command with remove_stale_keys, the Django setting CONSTANCE_DATABASE_PREFIX is not honored. That means that using the DatabaseBackend with a non-empty string prefix will result in all keys being dropped from the database. If CONSTANCE_DATABASE_CACHE_BACKEND is set to False, or if caching is enabled but the TTL of any item has expired, then the next usage of any configuration item will have its default value.
Steps to Reproduce
- In a Django project with
django-constance>2.6, use a non-empty string prefix:
# your/project/settings.py, where DJANGO_SETTINGS_MODULE=your.project.settings
CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
CONSTANCE_DATABASE_CACHE_BACKEND = None
CONSTANCE_DATABASE_PREFIX = "constance:"
CONSTANCE_CONFIG = {
"MY_FEATURE_ENABLED": (
True,
"Whether my feature is enabled",
)
}
- In a terminal, start your database and cache
- Start the dev server with
python manage.py runserver
- Navigate to the Django Admin Constance page and update
MY_FEATURE_ENABLED to False, being sure to save
- In a terminal, run the management command:
$ python manage.py constance remove_stale_keys
The following record will be deleted:
constance:MY_FEATURE_ENABLED {"__type__": "default", "__value__": false}
- Refresh the Django Admin Constance page. You'll see the default value of
True instead of the value previously set in step 4
Description
When running the
constancemanagement command withremove_stale_keys, the Django settingCONSTANCE_DATABASE_PREFIXis not honored. That means that using the DatabaseBackend with a non-empty string prefix will result in all keys being dropped from the database. IfCONSTANCE_DATABASE_CACHE_BACKENDis set toFalse, or if caching is enabled but the TTL of any item has expired, then the next usage of any configuration item will have its default value.Steps to Reproduce
django-constance>2.6, use a non-empty string prefix:python manage.py runserverMY_FEATURE_ENABLEDtoFalse, being sure to save$ python manage.py constance remove_stale_keys The following record will be deleted: constance:MY_FEATURE_ENABLED {"__type__": "default", "__value__": false}Trueinstead of the value previously set in step 4