Skip to content

Management command to remove stale keys doesn't respect CONSTANCE_DATABASE_PREFIX #633

@christherama

Description

@christherama

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

  1. 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",
      )
    }
  2. In a terminal, start your database and cache
  3. Start the dev server with python manage.py runserver
  4. Navigate to the Django Admin Constance page and update MY_FEATURE_ENABLED to False, being sure to save
  5. 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}
  6. Refresh the Django Admin Constance page. You'll see the default value of True instead of the value previously set in step 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions