summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2011-11-19 19:56:31 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2011-11-19 19:56:31 +0000
commitd0eb4693ab479ef0667cd5286ecc89c347b6b2de (patch)
tree37719ea2ecb115185430ee3c8afd7cb705691660 /django
parentc8c71057aad21d71b512a87cc4a7020e8abfb12f (diff)
Fixed #15255 -- Ensured createcachetable honors database routers.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17114 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/db/backends/spatialite/creation.py4
-rw-r--r--django/core/management/commands/createcachetable.py12
-rw-r--r--django/db/backends/creation.py4
3 files changed, 10 insertions, 10 deletions
diff --git a/django/contrib/gis/db/backends/spatialite/creation.py b/django/contrib/gis/db/backends/spatialite/creation.py
index ee5f9db336..03ea45da44 100644
--- a/django/contrib/gis/db/backends/spatialite/creation.py
+++ b/django/contrib/gis/db/backends/spatialite/creation.py
@@ -61,9 +61,7 @@ class SpatiaLiteCreation(DatabaseCreation):
for cache_alias in settings.CACHES:
cache = get_cache(cache_alias)
if isinstance(cache, BaseDatabaseCache):
- from django.db import router
- if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
- call_command('createcachetable', cache._table, database=self.connection.alias)
+ call_command('createcachetable', cache._table, database=self.connection.alias)
# Get a cursor (even though we don't need one yet). This has
# the side effect of initializing the test database.
diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index a6628a039a..287a036819 100644
--- a/django/core/management/commands/createcachetable.py
+++ b/django/core/management/commands/createcachetable.py
@@ -1,7 +1,8 @@
from optparse import make_option
+from django.core.cache.backends.db import BaseDatabaseCache
from django.core.management.base import LabelCommand
-from django.db import connections, transaction, models, DEFAULT_DB_ALIAS
+from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
class Command(LabelCommand):
help = "Creates the table needed to use the SQL cache backend."
@@ -18,8 +19,11 @@ class Command(LabelCommand):
requires_model_validation = False
def handle_label(self, tablename, **options):
- alias = options.get('database')
- connection = connections[alias]
+ db = options.get('database', DEFAULT_DB_ALIAS)
+ cache = BaseDatabaseCache(tablename, {})
+ if not router.allow_syncdb(db, cache.cache_model_class):
+ return
+ connection = connections[db]
fields = (
# "key" is a reserved word in MySQL, so use "cache_key" instead.
models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
@@ -50,4 +54,4 @@ class Command(LabelCommand):
curs.execute("\n".join(full_statement))
for statement in index_output:
curs.execute(statement)
- transaction.commit_unless_managed(using=alias)
+ transaction.commit_unless_managed(using=db)
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index f03df5d380..ce1da6d4c4 100644
--- a/django/db/backends/creation.py
+++ b/django/db/backends/creation.py
@@ -255,9 +255,7 @@ class BaseDatabaseCreation(object):
for cache_alias in settings.CACHES:
cache = get_cache(cache_alias)
if isinstance(cache, BaseDatabaseCache):
- from django.db import router
- if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
- call_command('createcachetable', cache._table, database=self.connection.alias)
+ call_command('createcachetable', cache._table, database=self.connection.alias)
# Get a cursor (even though we don't need one yet). This has
# the side effect of initializing the test database.