Skip to content

Commit 1d6c306

Browse files
committed
Edits
1 parent f3709fa commit 1d6c306

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

django_mongodb_backend/cache.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
113113
True,
114114
)
115115
except DuplicateKeyError:
116-
# Check the exception name to catch when the key exists.
117116
return False
118117
return True
119118

django_mongodb_backend/creation.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from django.conf import settings
2-
from django.core.management import call_command
2+
from django.core.cache import caches
33
from django.db.backends.base.creation import BaseDatabaseCreation
44

5+
from django_mongodb_backend.cache import MongoDBCache
6+
57

68
class DatabaseCreation(BaseDatabaseCreation):
79
def _execute_create_test_db(self, cursor, parameters, keepdb=False):
@@ -20,5 +22,12 @@ def _destroy_test_db(self, test_database_name, verbosity):
2022

2123
def create_test_db(self, *args, **kwargs):
2224
test_database_name = super().create_test_db(*args, **kwargs)
23-
call_command("createcachecollection", database=self.connection.alias)
25+
# Create cache collections
26+
for cache_alias in settings.CACHES:
27+
cache = caches[cache_alias]
28+
connection = cache._db
29+
if cache._collection_name in connection.introspection.table_names():
30+
continue
31+
cache = MongoDBCache(cache._collection_name, {})
32+
cache.create_indexes()
2433
return test_database_name

django_mongodb_backend/management/commands/createcachecollection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def check_collection(self, database, collection_name):
5050
if not router.allow_migrate_model(database, cache.cache_model_class):
5151
return
5252
connection = connections[database]
53-
5453
if collection_name in connection.introspection.table_names():
5554
if self.verbosity > 0:
5655
self.stdout.write("Cache collection '%s' already exists." % collection_name)

0 commit comments

Comments
 (0)