Skip to content

Add @async_unsafe to DatabaseWrapper methods as needed #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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