Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rolled back r16510, r16513 and r16514 because it wasn't ready.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16515 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 89c302cf3f63f35161bdb2c09c849b30f35136e2 1 parent b37dca1
Jannis Leidel authored
4  django/contrib/gis/db/backends/spatialite/creation.py
@@ -33,7 +33,9 @@ def create_test_db(self, verbosity=1, autoclobber=False):
33 33
         for cache_alias in settings.CACHES:
34 34
             cache = get_cache(cache_alias)
35 35
             if isinstance(cache, BaseDatabaseCache):
36  
-                call_command('createcachetable', cache._table, database=self.connection.alias)
  36
+                from django.db import router
  37
+                if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
  38
+                    call_command('createcachetable', cache._table, database=self.connection.alias)
37 39
         # Get a cursor (even though we don't need one yet). This has
38 40
         # the side effect of initializing the test database.
39 41
         cursor = self.connection.cursor()
12  django/core/management/commands/createcachetable.py
... ...
@@ -1,8 +1,7 @@
1 1
 from optparse import make_option
2 2
 
3 3
 from django.core.management.base import LabelCommand
4  
-from django.core.cache.backends.db import BaseDatabaseCache
5  
-from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
  4
+from django.db import connections, transaction, models, DEFAULT_DB_ALIAS
6 5
 
7 6
 class Command(LabelCommand):
8 7
     help = "Creates the table needed to use the SQL cache backend."
@@ -19,11 +18,8 @@ class Command(LabelCommand):
19 18
     requires_model_validation = False
20 19
 
21 20
     def handle_label(self, tablename, **options):
22  
-        db = options.get('database', DEFAULT_DB_ALIAS)
23  
-        cache = BaseDatabaseCache(tablename, {})
24  
-        if not router.allow_syncdb(db, cache.cache_model_class):
25  
-            return
26  
-        connection = connections[db]
  21
+        alias = options.get('database', DEFAULT_DB_ALIAS)
  22
+        connection = connections[alias]
27 23
         fields = (
28 24
             # "key" is a reserved word in MySQL, so use "cache_key" instead.
29 25
             models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
@@ -54,4 +50,4 @@ def handle_label(self, tablename, **options):
54 50
         curs.execute("\n".join(full_statement))
55 51
         for statement in index_output:
56 52
             curs.execute(statement)
57  
-        transaction.commit_unless_managed(using=db)
  53
+        transaction.commit_unless_managed(using=alias)
4  django/db/backends/creation.py
@@ -261,7 +261,9 @@ def create_test_db(self, verbosity=1, autoclobber=False):
261 261
         for cache_alias in settings.CACHES:
262 262
             cache = get_cache(cache_alias)
263 263
             if isinstance(cache, BaseDatabaseCache):
264  
-                call_command('createcachetable', cache._table, database=self.connection.alias)
  264
+                from django.db import router
  265
+                if router.allow_syncdb(self.connection.alias, cache.cache_model_class):
  266
+                    call_command('createcachetable', cache._table, database=self.connection.alias)
265 267
 
266 268
         # Get a cursor (even though we don't need one yet). This has
267 269
         # the side effect of initializing the test database.
41  tests/regressiontests/cache/tests.py
@@ -14,11 +14,10 @@
14 14
 from django.core import management
15 15
 from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
16 16
 from django.core.cache.backends.base import CacheKeyWarning, InvalidCacheBackendError
17  
-from django.db import router
18 17
 from django.http import HttpResponse, HttpRequest, QueryDict
19 18
 from django.middleware.cache import FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware
20  
-from django.test import RequestFactory, TestCase
21  
-from django.test.utils import get_warnings_state, restore_warnings_state, override_settings
  19
+from django.test import RequestFactory
  20
+from django.test.utils import get_warnings_state, restore_warnings_state
22 21
 from django.utils import translation
23 22
 from django.utils import unittest
24 23
 from django.utils.cache import patch_vary_headers, get_cache_key, learn_cache_key
@@ -759,42 +758,6 @@ def test_old_initialization(self):
759 758
         self.cache = get_cache('db://%s?max_entries=30&cull_frequency=0' % self._table_name)
760 759
         self.perform_cull_test(50, 18)
761 760
 
762  
-class DBCacheRouter(object):
763  
-    """A router that puts the cache table on the 'other' database."""
764  
-
765  
-    def db_for_read(self, model, **hints):
766  
-        if model._meta.app_label == 'django_cache':
767  
-            return 'other'
768  
-
769  
-    def db_for_write(self, model, **hints):
770  
-        if model._meta.app_label == 'django_cache':
771  
-            return 'other'
772  
-
773  
-    def allow_syncdb(self, db, model):
774  
-        if model._meta.app_label == 'django_cache':
775  
-            return db == 'other'
776  
-
777  
-
778  
-class CreateCacheTableForDBCacheTests(TestCase):
779  
-    multi_db = True
780  
-
781  
-    def test_createcachetable_observes_database_router(self):
782  
-        old_routers = router.routers
783  
-        try:
784  
-            router.routers = [DBCacheRouter()]
785  
-            # cache table should not be created on 'default'
786  
-            with self.assertNumQueries(0):
787  
-                management.call_command('createcachetable', 'cache_table',
788  
-                                        database='default',
789  
-                                        verbosity=0, interactive=False)
790  
-            # cache table should be created on 'other'
791  
-            with self.assertNumQueries(1):
792  
-                management.call_command('createcachetable', 'cache_table',
793  
-                                        database='other',
794  
-                                        verbosity=0, interactive=False)
795  
-        finally:
796  
-            router.routers = old_routers
797  
-
798 761
 
799 762
 class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
800 763
     backend_name = 'django.core.cache.backends.locmem.LocMemCache'

0 notes on commit 89c302c

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