mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #36369 -- Cleared additional cached properties in apps.clear_cache().
Thanks Clifford Gama for the report. Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
This commit is contained in:
committed by
Jacob Walls
parent
fd705912ff
commit
5ee651f255
@@ -100,6 +100,13 @@ class Options:
|
|||||||
"managers_map",
|
"managers_map",
|
||||||
"base_manager",
|
"base_manager",
|
||||||
"default_manager",
|
"default_manager",
|
||||||
|
"db_returning_fields",
|
||||||
|
"_property_names",
|
||||||
|
"pk_fields",
|
||||||
|
"total_unique_constraints",
|
||||||
|
"all_parents",
|
||||||
|
"swapped",
|
||||||
|
"verbose_name_raw",
|
||||||
}
|
}
|
||||||
REVERSE_PROPERTIES = {"related_objects", "fields_map", "_relation_tree"}
|
REVERSE_PROPERTIES = {"related_objects", "fields_map", "_relation_tree"}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from django.test import (
|
|||||||
skipUnlessDBFeature,
|
skipUnlessDBFeature,
|
||||||
)
|
)
|
||||||
from django.test.utils import extend_sys_path, isolate_apps
|
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 .models import SoAlternative, TotallyNormal, new_apps
|
||||||
from .one_config_app.apps import OneConfig
|
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_swappable_settings_name.cache_info().currsize, 0)
|
||||||
self.assertEqual(apps.get_models.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"])
|
@override_settings(INSTALLED_APPS=["apps.apps.RelabeledAppsConfig"])
|
||||||
def test_relabeling(self):
|
def test_relabeling(self):
|
||||||
self.assertEqual(apps.get_app_config("relabeled").name, "apps")
|
self.assertEqual(apps.get_app_config("relabeled").name, "apps")
|
||||||
|
|||||||
Reference in New Issue
Block a user