Skip to content

Commit 6de8a92

Browse files
committed
Check for replica set or sharded cluster
1 parent 4fafdeb commit 6de8a92

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

django_mongodb_backend/features.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
3636
supports_temporal_subtraction = True
3737
# MongoDB stores datetimes in UTC.
3838
supports_timezones = False
39-
# Not implemented: https://github.com/mongodb/django-mongodb-backend/issues/7
40-
supports_transactions = False
4139
supports_unspecified_pk = True
4240
uses_savepoints = False
4341

@@ -97,6 +95,22 @@ class DatabaseFeatures(BaseDatabaseFeatures):
9795
"expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or",
9896
}
9997

98+
@cached_property
99+
def supports_transactions(self):
100+
"""Confirm support for transactions."""
101+
is_replica_set = False
102+
is_sharded_cluster = False
103+
with self.connection.cursor():
104+
client = self.connection.connection
105+
hello_response = client.admin.command("hello")
106+
if "setName" in hello_response:
107+
is_replica_set = True
108+
if "msg" in client.admin.command("hello") and hello_response["msg"] == "isdbgrid":
109+
is_sharded_cluster = True
110+
if is_replica_set or is_sharded_cluster:
111+
return True
112+
return False
113+
100114
@cached_property
101115
def django_test_expected_failures(self):
102116
expected_failures = super().django_test_expected_failures

0 commit comments

Comments
 (0)