Skip to content

Commit eb26848

Browse files
committed
Add @async_unsafe to DatabaseWrapper methods as needed
1 parent 1af5673 commit eb26848

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

django_mongodb_backend/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from django.core.exceptions import ImproperlyConfigured
55
from django.db.backends.base.base import BaseDatabaseWrapper
6+
from django.utils.asyncio import async_unsafe
67
from pymongo.collection import Collection
78
from pymongo.driver_info import DriverInfo
89
from pymongo.mongo_client import MongoClient
@@ -172,6 +173,7 @@ def get_connection_params(self):
172173
**settings_dict["OPTIONS"],
173174
}
174175

176+
@async_unsafe
175177
def get_new_connection(self, conn_params):
176178
return MongoClient(**conn_params, driver=self._driver_info())
177179

@@ -189,11 +191,13 @@ def _rollback(self):
189191
def set_autocommit(self, autocommit, force_begin_transaction_with_broken_autocommit=False):
190192
pass
191193

194+
@async_unsafe
192195
def close(self):
193196
super().close()
194197
with contextlib.suppress(AttributeError):
195198
del self.database
196199

200+
@async_unsafe
197201
def cursor(self):
198202
return Cursor()
199203

0 commit comments

Comments
 (0)