Skip to content

Commit 4ae108b

Browse files
committed
Fix range lookup includes incorrect values.
1 parent 41598ec commit 4ae108b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

django_mongodb/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ def _isnull_operator(a, b):
102102
"lte": lambda a, b: {"$lte": [a, b]},
103103
"in": lambda a, b: {"$in": [a, b]},
104104
"isnull": _isnull_operator,
105-
"range": lambda a, b: {"$and": [{"$gte": [a, b[0]]}, {"$lte": [a, b[1]]}]},
105+
"range": lambda a, b: {
106+
"$and": [
107+
{"$or": [DatabaseWrapper._isnull_operator(b[0], True), {"$gte": [a, b[0]]}]},
108+
{"$or": [DatabaseWrapper._isnull_operator(b[1], True), {"$lte": [a, b[1]]}]},
109+
]
110+
},
106111
"iexact": lambda a, b: regex_match(a, ("^", b, {"$literal": "$"}), insensitive=True),
107112
"startswith": lambda a, b: regex_match(a, ("^", b)),
108113
"istartswith": lambda a, b: regex_match(a, ("^", b), insensitive=True),

django_mongodb/features.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
5757
"db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_trunc_timezone_applied_before_truncation",
5858
# Length of null considered zero rather than null.
5959
"db_functions.text.test_length.LengthTests.test_basic",
60-
# range lookup includes incorrect values.
61-
"expressions.tests.IterableLookupInnerExpressionsTests.test_expressions_in_lookups_join_choice",
6260
# Unexpected alias_refcount in alias_map.
6361
"queries.tests.Queries1Tests.test_order_by_tables",
6462
# The $sum aggregation returns 0 instead of None for null.

0 commit comments

Comments
 (0)