Skip to content

Comments

swev-id: django__django-17029 - Clear get_swappable_settings_name cache in Apps.clear_cache() [skip ci]#538

Open
casey-brooks wants to merge 1 commit intodjango__django-17029from
noa/issue-535
Open

swev-id: django__django-17029 - Clear get_swappable_settings_name cache in Apps.clear_cache() [skip ci]#538
casey-brooks wants to merge 1 commit intodjango__django-17029from
noa/issue-535

Conversation

@casey-brooks
Copy link

Resolves #535

Summary

  • clear Apps.get_swappable_settings_name when purging registry caches
  • add a regression test ensuring the swappable settings cache is purged when INSTALLED_APPS changes

Reproduction

Run the minimal script from the issue on the base branch:

PYTHONPATH=/workspace/django source .venv/bin/activate
PYTHONPATH=/workspace/django python - <<'PY'
import django
from django.conf import settings
from django.apps import apps
from django.test.utils import override_settings

settings.configure(
    INSTALLED_APPS=['django.contrib.contenttypes', 'django.contrib.auth'],
    SECRET_KEY='test',
)
django.setup()

first = apps.get_swappable_settings_name('auth.User')
assert first == 'AUTH_USER_MODEL'

with override_settings(INSTALLED_APPS=['django.contrib.contenttypes']):
    second = apps.get_swappable_settings_name('auth.User')
    assert second is None
PY

Observed failure before the fix:

first: AUTH_USER_MODEL
second: AUTH_USER_MODEL
Traceback (most recent call last):
  File "<stdin>", line 19, in <module>
AssertionError

Testing

  • PYTHONPATH=/workspace/django DJANGO_SETTINGS_MODULE=tests.test_sqlite python tests/runtests.py apps.tests.AppsTests.test_clear_cache_clears_swappable_settings_cache --parallel=1
  • PYTHONPATH=/workspace/django DJANGO_SETTINGS_MODULE=tests.test_sqlite python tests/runtests.py apps --parallel=1

Local tests pass after the fix.

@casey-brooks casey-brooks requested a review from a team December 24, 2025 18:14
@casey-brooks
Copy link
Author

Test & Lint Summary

  • PYTHONPATH=/workspace/django DJANGO_SETTINGS_MODULE=tests.test_sqlite python tests/runtests.py apps.tests.AppsTests.test_clear_cache_clears_swappable_settings_cache --parallel=1 (pass)
  • PYTHONPATH=/workspace/django DJANGO_SETTINGS_MODULE=tests.test_sqlite python tests/runtests.py apps --parallel=1 (pass)
  • flake8 django/apps/registry.py tests/apps/tests.py (pass)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Clearing the swappable settings cache keeps Apps.clear_cache() consistent with its contract, and the regression test covers the reported scenario.

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good to me. Clearing get_swappable_settings_name alongside get_models keeps Apps.clear_cache() consistent with its contract, and the regression test fails before the change and passes after. Thanks!

Copy link
Collaborator

@rowan-stein rowan-stein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The cache clear for get_swappable_settings_name in Apps.clear_cache() is correct, and the regression test passes locally.

@rowan-stein rowan-stein changed the base branch from django__django-17029 to main January 11, 2026 20:09
@rowan-stein rowan-stein changed the base branch from main to django__django-17029 January 12, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apps.clear_cache() should also clear get_swappable_settings_name cache

3 participants