Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Apps.clear_cache().

This avoid leaking implementation details to tests that swap models.
  • Loading branch information...
commit 21f22f9544b0c6c4390bcd1acd98e6e5201ed83e 1 parent 82aadbb
@aaugustin aaugustin authored
Showing with 17 additions and 9 deletions.
  1. +16 −8 django/apps/registry.py
  2. +1 −1  django/contrib/auth/tests/test_basic.py
View
24 django/apps/registry.py
@@ -84,7 +84,7 @@ def populate_apps(self, installed_apps=None):
app_config = AppConfig.create(entry)
self.app_configs[app_config.label] = app_config
- self.get_models.cache_clear()
+ self.clear_cache()
self._apps_loaded = True
def populate_models(self):
@@ -133,7 +133,7 @@ def populate_models(self):
del self._postponed
- self.get_models.cache_clear()
+ self.clear_cache()
self._models_loaded = True
@property
@@ -248,7 +248,7 @@ def register_model(self, app_label, model):
"Conflicting '%s' models in application '%s': %s and %s." %
(model_name, app_label, app_models[model_name], model))
app_models[model_name] = model
- self.get_models.cache_clear()
+ self.clear_cache()
def has_app(self, app_name):
"""
@@ -299,14 +299,14 @@ def set_available_apps(self, available):
(label, app_config)
for label, app_config in self.app_configs.items()
if app_config.name in available)
- self.get_models.cache_clear()
+ self.clear_cache()
def unset_available_apps(self):
"""
Cancels a previous call to set_available_apps().
"""
self.app_configs = self.stored_app_configs.pop()
- self.get_models.cache_clear()
+ self.clear_cache()
def set_installed_apps(self, installed):
"""
@@ -327,7 +327,7 @@ def set_installed_apps(self, installed):
"""
self.stored_app_configs.append((self.app_configs, self._apps_loaded, self._models_loaded))
self.app_configs = OrderedDict()
- self.get_models.cache_clear()
+ self.clear_cache()
self._apps_loaded = False
self.populate_apps(installed)
self._models_loaded = False
@@ -338,7 +338,15 @@ def unset_installed_apps(self):
Cancels a previous call to set_installed_apps().
"""
self.app_configs, self._apps_loaded, self._models_loaded = self.stored_app_configs.pop()
- self.get_models.cache_clear()
+ self.clear_cache()
+
+ def clear_cache(self):
+ """
+ Clears all internal caches, for methods that alter the app registry.
+
+ This is mostly used in tests.
+ """
+ self.clear_cache()
@charettes Collaborator

self.get_models.cache_clear()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
### DEPRECATED METHODS GO BELOW THIS LINE ###
@@ -353,7 +361,7 @@ def load_app(self, app_name):
app_config = AppConfig.create(app_name)
app_config.import_models(self.all_models[app_config.label])
self.app_configs[app_config.label] = app_config
- self.get_models.cache_clear()
+ self.clear_cache()
return app_config.models_module
def app_cache_ready(self):
View
2  django/contrib/auth/tests/test_basic.py
@@ -26,7 +26,7 @@ def user_model_swapped(**kwargs):
# Reset User manager
setattr(User, 'objects', User._default_manager)
ensure_default_manager(User)
- apps.get_models.cache_clear()
+ apps.clear_cache()
def mock_inputs(inputs):
@charettes

self.get_models.cache_clear()?

Please sign in to comment.
Something went wrong with that request. Please try again.