Skip to content

Commit

Permalink
dropped support for MongoDB 5.0
Browse files Browse the repository at this point in the history
It was end of life in October 2024.
  • Loading branch information
timgraham committed Jan 27, 2025
1 parent 6343462 commit af69b50
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ tasks:

buildvariants:
- name: tests-5-noauth-nossl
display_name: Run Tests 5.0 NoAuth NoSSL
display_name: Run Tests 6.0 NoAuth NoSSL
run_on: rhel87-small
expansions:
MONGODB_VERSION: "5.0"
MONGODB_VERSION: "6.0"
TOPOLOGY: server
AUTH: "noauth"
SSL: "nossl"
tasks:
- name: run-tests

- name: tests-5-auth-ssl
display_name: Run Tests 5.0 Auth SSL
display_name: Run Tests 6.0 Auth SSL
run_on: rhel87-small
expansions:
MONGODB_VERSION: "5.0"
MONGODB_VERSION: "6.0"
TOPOLOGY: server
AUTH: "auth"
SSL: "ssl"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ jobs:
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 5.0
mongodb-version: 6.0
- name: Run tests
run: python3 django_repo/tests/runtests_.py
13 changes: 1 addition & 12 deletions django_mongodb_backend/features.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import operator

from django.db.backends.base.features import BaseDatabaseFeatures
from django.utils.functional import cached_property


class DatabaseFeatures(BaseDatabaseFeatures):
minimum_database_version = (5, 0)
minimum_database_version = (6, 0)
allow_sliced_subqueries_with_in = False
allows_multiple_constraints_on_same_fields = False
can_create_inline_fk = False
Expand All @@ -24,10 +22,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_expression_indexes = False
supports_foreign_keys = False
supports_ignore_conflicts = False
# Before MongoDB 6.0, $in cannot be used in partialFilterExpression.
supports_in_index_operator = property(operator.attrgetter("is_mongodb_6_0"))
# Before MongoDB 6.0, $or cannot be used in partialFilterExpression.
supports_or_index_operator = property(operator.attrgetter("is_mongodb_6_0"))
supports_json_field_contains = False
# BSON Date type doesn't support microsecond precision.
supports_microsecond_precision = False
Expand Down Expand Up @@ -97,16 +91,11 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_right_null",
"expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or",
}
_django_test_expected_failures_partial_expression_in = {
"schema.tests.SchemaTests.test_remove_ignored_unique_constraint_not_create_fk_index",
}

@cached_property
def django_test_expected_failures(self):
expected_failures = super().django_test_expected_failures
expected_failures.update(self._django_test_expected_failures)
if not self.supports_in_index_operator:
expected_failures.update(self._django_test_expected_failures_partial_expression_in)
if not self.is_mongodb_6_3:
expected_failures.update(self._django_test_expected_failures_bitwise)
return expected_failures
Expand Down
10 changes: 0 additions & 10 deletions django_mongodb_backend/indexes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db import NotSupportedError
from django.db.models import Index
from django.db.models.fields.related_lookups import In
from django.db.models.lookups import BuiltinLookup
from django.db.models.sql.query import Query
from django.db.models.sql.where import AND, XOR, WhereNode
Expand Down Expand Up @@ -37,20 +36,12 @@ def builtin_lookup_idx(self, compiler, connection):
return {lhs_mql: {operator: value}}


def in_idx(self, compiler, connection):
if not connection.features.supports_in_index_operator:
raise NotSupportedError("MongoDB < 6.0 does not support the 'in' lookup in indexes.")
return builtin_lookup_idx(self, compiler, connection)


def where_node_idx(self, compiler, connection):
if self.connector == AND:
operator = "$and"
elif self.connector == XOR:
raise NotSupportedError("MongoDB does not support the '^' operator lookup in indexes.")
else:
if not connection.features.supports_in_index_operator:
raise NotSupportedError("MongoDB < 6.0 does not support the '|' operator in indexes.")
operator = "$or"
if self.negated:
raise NotSupportedError("MongoDB does not support the '~' operator in indexes.")
Expand All @@ -69,6 +60,5 @@ def where_node_idx(self, compiler, connection):

def register_indexes():
BuiltinLookup.as_mql_idx = builtin_lookup_idx
In.as_mql_idx = in_idx
Index._get_condition_mql = _get_condition_mql
WhereNode.as_mql_idx = where_node_idx
25 changes: 1 addition & 24 deletions tests/indexes_/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import NotSupportedError, connection
from django.db.models import Index, Q
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test import TestCase

from .models import Article

Expand Down Expand Up @@ -46,26 +46,6 @@ def test_xor_not_supported(self):
condition=Q(pk=True) ^ Q(pk=False),
)._get_condition_mql(Article, schema_editor=editor)

@skipIfDBFeature("supports_or_index_operator")
def test_or_not_supported(self):
msg = "MongoDB < 6.0 does not support the '|' operator in indexes."
with self.assertRaisesMessage(NotSupportedError, msg), connection.schema_editor() as editor:
Index(
name="test",
fields=["headline"],
condition=Q(pk=True) | Q(pk=False),
)._get_condition_mql(Article, schema_editor=editor)

@skipIfDBFeature("supports_in_index_operator")
def test_in_not_supported(self):
msg = "MongoDB < 6.0 does not support the 'in' lookup in indexes."
with self.assertRaisesMessage(NotSupportedError, msg), connection.schema_editor() as editor:
Index(
name="test",
fields=["headline"],
condition=Q(pk__in=[True]),
)._get_condition_mql(Article, schema_editor=editor)

def test_operations(self):
operators = (
("gt", "$gt"),
Expand All @@ -86,7 +66,6 @@ def test_operations(self):
)
self.assertAddRemoveIndex(editor, Article, index)

@skipUnlessDBFeature("supports_in_index_operator")
def test_composite_index(self):
with connection.schema_editor() as editor:
index = Index(
Expand All @@ -110,8 +89,6 @@ def test_composite_op_index(self):
(operator.or_, "$or"),
(operator.and_, "$and"),
)
if not connection.features.supports_or_index_operator:
operators = operators[1:]
for op, mongo_operator in operators:
with self.subTest(operator=op), connection.schema_editor() as editor:
index = Index(
Expand Down

0 comments on commit af69b50

Please sign in to comment.