Skip to content

Commit

Permalink
Add @async_unsafe to DatabaseWrapper methods as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Feb 11, 2025
1 parent 1af5673 commit eb26848
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django_mongodb_backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.core.exceptions import ImproperlyConfigured
from django.db.backends.base.base import BaseDatabaseWrapper
from django.utils.asyncio import async_unsafe
from pymongo.collection import Collection
from pymongo.driver_info import DriverInfo
from pymongo.mongo_client import MongoClient
Expand Down Expand Up @@ -172,6 +173,7 @@ def get_connection_params(self):
**settings_dict["OPTIONS"],
}

@async_unsafe
def get_new_connection(self, conn_params):
return MongoClient(**conn_params, driver=self._driver_info())

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

@async_unsafe
def close(self):
super().close()
with contextlib.suppress(AttributeError):
del self.database

@async_unsafe
def cursor(self):
return Cursor()

Expand Down

0 comments on commit eb26848

Please sign in to comment.