Skip to content

Commit f5dbacb

Browse files
committed
fix persistent connections
Without autocommit set, BaseDatabaseWrapper.close_if_unusable_or_obsolete() short-circuits early and always closes the connection after each request.
1 parent eb26848 commit f5dbacb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: django_mongodb_backend/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def _rollback(self):
189189
pass
190190

191191
def set_autocommit(self, autocommit, force_begin_transaction_with_broken_autocommit=False):
192-
pass
192+
self.autocommit = autocommit
193193

194194
@async_unsafe
195195
def close(self):

Diff for: tests/backend_/test_base.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.core.exceptions import ImproperlyConfigured
22
from django.db import connection
3-
from django.test import SimpleTestCase
3+
from django.test import SimpleTestCase, TestCase
44

55
from django_mongodb_backend.base import DatabaseWrapper
66

@@ -12,3 +12,12 @@ def test_database_name_empty(self):
1212
msg = 'settings.DATABASES is missing the "NAME" value.'
1313
with self.assertRaisesMessage(ImproperlyConfigured, msg):
1414
DatabaseWrapper(settings).get_connection_params()
15+
16+
17+
class DatabaseWrapperConnectionTests(TestCase):
18+
def test_set_autocommit(self):
19+
self.assertIs(connection.get_autocommit(), True)
20+
connection.set_autocommit(False)
21+
self.assertIs(connection.get_autocommit(), False)
22+
connection.set_autocommit(True)
23+
self.assertIs(connection.get_autocommit(), True)

0 commit comments

Comments
 (0)