Skip to content

Commit 5c29684

Browse files
authored
make QuerySet.exclude() range lookup exclude data with a null boundary
1 parent fba8892 commit 5c29684

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
@@ -54,8 +54,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
5454
"db_functions.datetime.test_extract_trunc.DateFunctionWithTimeZoneTests.test_trunc_timezone_applied_before_truncation",
5555
# Length of null considered zero rather than null.
5656
"db_functions.text.test_length.LengthTests.test_basic",
57-
# range lookup includes incorrect values.
58-
"expressions.tests.IterableLookupInnerExpressionsTests.test_expressions_in_lookups_join_choice",
5957
# Unexpected alias_refcount in alias_map.
6058
"queries.tests.Queries1Tests.test_order_by_tables",
6159
# The $sum aggregation returns 0 instead of None for null.

0 commit comments

Comments
 (0)