Code

Ticket #15255: 15255.diff

File 15255.diff, 3.3 KB (added by aaugustin, 3 years ago)
Line 
1Index: django/db/backends/creation.py
2===================================================================
3--- django/db/backends/creation.py      (revision 15655)
4+++ django/db/backends/creation.py      (working copy)
5@@ -380,9 +380,7 @@
6         for cache_alias in settings.CACHES:
7             cache = get_cache(cache_alias)
8             if isinstance(cache, BaseDatabaseCache):
9-                from django.db import router
10-                if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
11-                    call_command('createcachetable', cache._table, database=self.connection.alias)
12+                call_command('createcachetable', cache._table, database=self.connection.alias)
13 
14         # Get a cursor (even though we don't need one yet). This has
15         # the side effect of initializing the test database.
16Index: django/core/management/commands/createcachetable.py
17===================================================================
18--- django/core/management/commands/createcachetable.py (revision 15655)
19+++ django/core/management/commands/createcachetable.py (working copy)
20@@ -1,7 +1,8 @@
21 from optparse import make_option
22 
23 from django.core.management.base import LabelCommand
24-from django.db import connections, transaction, models, DEFAULT_DB_ALIAS
25+from django.core.cache.backends.db import BaseDatabaseCache
26+from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
27 
28 class Command(LabelCommand):
29     help = "Creates the table needed to use the SQL cache backend."
30@@ -18,8 +19,11 @@
31     requires_model_validation = False
32 
33     def handle_label(self, tablename, **options):
34-        alias = options.get('database', DEFAULT_DB_ALIAS)
35-        connection = connections[alias]
36+        db = options.get('database', DEFAULT_DB_ALIAS)
37+        cache = BaseDatabaseCache(tablename, {})
38+        if not router.allow_syncdb(db, cache.cache_model_class):
39+            return
40+        connection = connections[db]
41         fields = (
42             # "key" is a reserved word in MySQL, so use "cache_key" instead.
43             models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
44@@ -50,4 +54,4 @@
45         curs.execute("\n".join(full_statement))
46         for statement in index_output:
47             curs.execute(statement)
48-        transaction.commit_unless_managed(using=alias)
49+        transaction.commit_unless_managed(using=db)
50Index: django/contrib/gis/db/backends/spatialite/creation.py
51===================================================================
52--- django/contrib/gis/db/backends/spatialite/creation.py       (revision 15655)
53+++ django/contrib/gis/db/backends/spatialite/creation.py       (working copy)
54@@ -33,9 +33,7 @@
55         for cache_alias in settings.CACHES:
56             cache = get_cache(cache_alias)
57             if isinstance(cache, BaseDatabaseCache):
58-                from django.db import router
59-                if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
60-                    call_command('createcachetable', cache._table, database=self.connection.alias)
61+                call_command('createcachetable', cache._table, database=self.connection.alias)
62         # Get a cursor (even though we don't need one yet). This has
63         # the side effect of initializing the test database.
64         cursor = self.connection.cursor()