diff --git a/django_mongodb/base.py b/django_mongodb/base.py index 0e4687139..8efcbb8e6 100644 --- a/django_mongodb/base.py +++ b/django_mongodb/base.py @@ -102,7 +102,12 @@ def _isnull_operator(a, b): "lte": lambda a, b: {"$lte": [a, b]}, "in": lambda a, b: {"$in": [a, b]}, "isnull": _isnull_operator, - "range": lambda a, b: {"$and": [{"$gte": [a, b[0]]}, {"$lte": [a, b[1]]}]}, + "range": lambda a, b: { + "$and": [ + {"$or": [DatabaseWrapper._isnull_operator(b[0], True), {"$gte": [a, b[0]]}]}, + {"$or": [DatabaseWrapper._isnull_operator(b[1], True), {"$lte": [a, b[1]]}]}, + ] + }, "iexact": lambda a, b: regex_match(a, ("^", b, {"$literal": "$"}), insensitive=True), "startswith": lambda a, b: regex_match(a, ("^", b)), "istartswith": lambda a, b: regex_match(a, ("^", b), insensitive=True), diff --git a/django_mongodb/features.py b/django_mongodb/features.py index d8e6b34cc..335d49e3d 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -54,8 +54,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): "db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_trunc_timezone_applied_before_truncation", # Length of null considered zero rather than null. "db_functions.text.test_length.LengthTests.test_basic", - # range lookup includes incorrect values. - "expressions.tests.IterableLookupInnerExpressionsTests.test_expressions_in_lookups_join_choice", # Unexpected alias_refcount in alias_map. "queries.tests.Queries1Tests.test_order_by_tables", # The $sum aggregation returns 0 instead of None for null.