Skip to content

Commit d4bee63

Browse files
committed
add expressions expected test failures for MongoDB < 6.3
1 parent b9bfcd8 commit d4bee63

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

django_mongodb/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,7 @@ def close(self):
167167

168168
def cursor(self):
169169
return Cursor()
170+
171+
def get_database_version(self):
172+
"""Return a tuple of the database's version."""
173+
return tuple(self.connection.server_info()["versionArray"])

django_mongodb/features.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.db.backends.base.features import BaseDatabaseFeatures
2+
from django.utils.functional import cached_property
23

34

45
class DatabaseFeatures(BaseDatabaseFeatures):
@@ -17,7 +18,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
1718
supports_transactions = False
1819
uses_savepoints = False
1920

20-
django_test_expected_failures = {
21+
_django_test_expected_failures = {
2122
# Database defaults not supported: bson.errors.InvalidDocument:
2223
# cannot encode object: <django.db.models.expressions.DatabaseDefault
2324
"basic.tests.ModelInstanceCreationTests.test_save_primary_with_db_default",
@@ -60,6 +61,23 @@ class DatabaseFeatures(BaseDatabaseFeatures):
6061
# Length of null considered zero rather than null.
6162
"db_functions.text.test_length.LengthTests.test_basic",
6263
}
64+
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
65+
_django_test_expected_failures_bitwise = {
66+
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_and",
67+
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_or",
68+
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor",
69+
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_null",
70+
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_right_null",
71+
"expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or",
72+
}
73+
74+
@cached_property
75+
def django_test_expected_failures(self):
76+
expected_failures = super().django_test_expected_failures
77+
expected_failures.update(self._django_test_expected_failures)
78+
if not self.is_mongodb_6_3:
79+
expected_failures.update(self._django_test_expected_failures_bitwise)
80+
return expected_failures
6381

6482
django_test_skips = {
6583
"Insert expressions aren't supported.": {
@@ -336,3 +354,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
336354
"db_functions.comparison.test_cast.CastTests.test_cast_to_duration",
337355
},
338356
}
357+
358+
@cached_property
359+
def is_mongodb_6_3(self):
360+
return self.connection.get_database_version() >= (6, 3)

0 commit comments

Comments
 (0)