diff options
| author | Senthil Kumar <jrsenthil.kumar23@gmail.com> | 2025-07-16 20:54:21 +0800 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-09-19 14:57:05 -0400 |
| commit | 5ee651f2555f3258b136f6e8be90f018fd8ffbf0 (patch) | |
| tree | e469a06dc941ce2b06925bce09e0514d4cc89ecb /tests/apps/tests.py | |
| parent | fd705912fff168d10c806568a222dfa25e3bb6a0 (diff) | |
Fixed #36369 -- Cleared additional cached properties in apps.clear_cache().
Thanks Clifford Gama for the report.
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Diffstat (limited to 'tests/apps/tests.py')
| -rw-r--r-- | tests/apps/tests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/apps/tests.py b/tests/apps/tests.py index 0f395b7fc3..ce7e19be1d 100644 --- a/tests/apps/tests.py +++ b/tests/apps/tests.py @@ -14,6 +14,7 @@ from django.test import ( skipUnlessDBFeature, ) from django.test.utils import extend_sys_path, isolate_apps +from django.utils.functional import cached_property from .models import SoAlternative, TotallyNormal, new_apps from .one_config_app.apps import OneConfig @@ -215,6 +216,27 @@ class AppsTests(SimpleTestCase): self.assertEqual(apps.get_swappable_settings_name.cache_info().currsize, 0) self.assertEqual(apps.get_models.cache_info().currsize, 0) + @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) + def test_cached_properties_cleared_after_cache_clear(self): + opts = apps.get_model("admin", "LogEntry")._meta + + cached_properties = [ + name + for name, attr in models.options.Options.__dict__.items() + if isinstance(attr, cached_property) + ] + + # Access each cached property to populate the cache. + for attr_name in cached_properties: + getattr(opts, attr_name) + self.assertIn(attr_name, opts.__dict__) + + apps.clear_cache() + + for attr_name in cached_properties: + with self.subTest(property=attr_name): + self.assertNotIn(attr_name, opts.__dict__) + @override_settings(INSTALLED_APPS=["apps.apps.RelabeledAppsConfig"]) def test_relabeling(self): self.assertEqual(apps.get_app_config("relabeled").name, "apps") |
