diff --git a/django_mongodb_backend/base.py b/django_mongodb_backend/base.py index 63375814c..683afe605 100644 --- a/django_mongodb_backend/base.py +++ b/django_mongodb_backend/base.py @@ -159,6 +159,11 @@ def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): super().__init__(settings_dict, alias=alias) self.session = None + def check_settings(self): + super().check_settings() + if not self.settings_dict["AUTOCOMMIT"]: + raise ImproperlyConfigured("MongoDB does not support AUTOCOMMIT=False.") + def get_collection(self, name, **kwargs): collection = Collection(self.database, name, **kwargs) if self.queries_logged: diff --git a/docs/source/ref/database.rst b/docs/source/ref/database.rst index 0abd3637f..0a815941d 100644 --- a/docs/source/ref/database.rst +++ b/docs/source/ref/database.rst @@ -58,6 +58,10 @@ default behavior of autocommit mode. Each query is immediately committed to the database. Django's transaction management APIs, such as :func:`~django.db.transaction.atomic`, function as no-ops. +:ref:`Deactivating transaction management ` +by setting :setting:`AUTOCOMMIT ` to ``False`` in the +:setting:`DATABASES` setting isn't supported. + .. _transactions-limitations: Limitations diff --git a/tests/backend_/test_base.py b/tests/backend_/test_base.py index 9d4e7006f..bf8a143d0 100644 --- a/tests/backend_/test_base.py +++ b/tests/backend_/test_base.py @@ -1,3 +1,5 @@ +import copy + from django.core.exceptions import ImproperlyConfigured from django.db import connection from django.db.backends.signals import connection_created @@ -14,6 +16,14 @@ def test_database_name_empty(self): with self.assertRaisesMessage(ImproperlyConfigured, msg): DatabaseWrapper(settings).get_connection_params() + def test_autocommit_false(self): + new_connection = connection.copy() + new_connection.settings_dict = copy.deepcopy(connection.settings_dict) + new_connection.settings_dict["AUTOCOMMIT"] = False + msg = "MongoDB does not support AUTOCOMMIT=False." + with self.assertRaisesMessage(ImproperlyConfigured, msg): + new_connection.check_settings() + class DatabaseWrapperConnectionTests(TransactionTestCase): available_apps = ["backend_"]