Jelajahi Sumber

Fixed #34687 -- Made Apps.clear_cache() clear get_swappable_settings_name() cache.

sobolevn 1 tahun lalu
induk
melakukan
5820fc4485
3 mengubah file dengan 13 tambahan dan 0 penghapusan
  1. 1 0
      AUTHORS
  2. 1 0
      django/apps/registry.py
  3. 11 0
      tests/apps/tests.py

+ 1 - 0
AUTHORS

@@ -747,6 +747,7 @@ answer newbie questions, and generally made Django that much better:
     Nicolas Lara <nicolaslara@gmail.com>
     Nicolas Noé <nicolas@niconoe.eu>
     Nikita Marchant <nikita.marchant@gmail.com>
+    Nikita Sobolev <mail@sobolevn.me>
     Niran Babalola <niran@niran.org>
     Nis Jørgensen <nis@superlativ.dk>
     Nowell Strite <https://nowell.strite.org/>

+ 1 - 0
django/apps/registry.py

@@ -373,6 +373,7 @@ class Apps:
 
         This is mostly used in tests.
         """
+        self.get_swappable_settings_name.cache_clear()
         # Call expire cache on each model. This will purge
         # the relation tree and the fields cache.
         self.get_models.cache_clear()

+ 11 - 0
tests/apps/tests.py

@@ -197,6 +197,17 @@ class AppsTests(SimpleTestCase):
         with self.assertRaises(ValueError):
             apps.get_model("admin_LogEntry")
 
+    @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS)
+    def test_clear_cache(self):
+        # Set cache.
+        self.assertIsNone(apps.get_swappable_settings_name("admin.LogEntry"))
+        apps.get_models()
+
+        apps.clear_cache()
+
+        self.assertEqual(apps.get_swappable_settings_name.cache_info().currsize, 0)
+        self.assertEqual(apps.get_models.cache_info().currsize, 0)
+
     @override_settings(INSTALLED_APPS=["apps.apps.RelabeledAppsConfig"])
     def test_relabeling(self):
         self.assertEqual(apps.get_app_config("relabeled").name, "apps")