1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Removed module-level functions for the app cache.

Since the original ones in django.db.models.loading were kept only for
backwards compatibility, there's no need to recreate them. However, many
internals of Django still relied on them.

They were also imported in django.db.models. They never appear in the
documentation, except a quick mention of get_models and get_app in the
1.2 release notes to document an edge case in GIS. I don't think that
makes them a public API.

This commit doesn't change the overall amount of global state but
clarifies that it's tied to the app_cache object instead of hiding it
behind half a dozen functions.
This commit is contained in:
Aymeric Augustin
2013-12-11 23:31:34 +01:00
parent 334551339d
commit 8662654d6d
55 changed files with 226 additions and 220 deletions

View File

@@ -6,7 +6,7 @@ import copy
import os
import shutil
from django.apps.cache import cache
from django.apps import app_cache
from django.core.management import call_command, CommandError
from django.test.utils import override_settings
from django.utils import six
@@ -132,11 +132,11 @@ class MakeMigrationsTests(MigrationTestBase):
self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
self.migration_dir = os.path.join(self.test_dir, 'migrations_%d' % self.creation_counter)
self.migration_pkg = "migrations.migrations_%d" % self.creation_counter
self._old_app_models = copy.deepcopy(cache.app_models)
self._old_app_models = copy.deepcopy(app_cache.app_models)
def tearDown(self):
cache.app_models = self._old_app_models
cache._get_models_cache = {}
app_cache.app_models = self._old_app_models
app_cache._get_models_cache = {}
os.chdir(self.test_dir)
try:
@@ -152,7 +152,7 @@ class MakeMigrationsTests(MigrationTestBase):
def test_files_content(self):
self.assertTableNotExists("migrations_unicodemodel")
cache.register_models('migrations', UnicodeModel)
app_cache.register_models('migrations', UnicodeModel)
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
call_command("makemigrations", "migrations", verbosity=0)
@@ -188,7 +188,7 @@ class MakeMigrationsTests(MigrationTestBase):
def test_failing_migration(self):
#21280 - If a migration fails to serialize, it shouldn't generate an empty file.
cache.register_models('migrations', UnserializableModel)
app_cache.register_models('migrations', UnserializableModel)
with six.assertRaisesRegex(self, ValueError, r'Cannot serialize'):
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):