Skip to content

Commit 3beb915

Browse files
committed
fix lt/lte lookup
1 parent 4419f33 commit 3beb915

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

django_mongodb_backend/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ def _isnull_operator(a, b):
121121
"gte": lambda a, b: {"$gte": [a, b]},
122122
# MongoDB considers null less than zero. Exclude null values to match
123123
# SQL behavior.
124-
"lt": lambda a, b: {"$and": [{"$lt": [a, b]}, {"$ne": [a, None]}]},
125-
"lte": lambda a, b: {"$and": [{"$lte": [a, b]}, {"$ne": [a, None]}]},
124+
"lt": lambda a, b: {"$and": [{"$lt": [a, b]}, DatabaseWrapper._isnull_operator(a, False)]},
125+
"lte": lambda a, b: {
126+
"$and": [{"$lte": [a, b]}, DatabaseWrapper._isnull_operator(a, False)]
127+
},
126128
"in": lambda a, b: {"$in": [a, b]},
127129
"isnull": _isnull_operator,
128130
"range": lambda a, b: {

tests/model_fields_/test_polymorphic_embedded_model.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import timedelta
22
from decimal import Decimal
3-
from unittest import expectedFailure
43

54
from django.core.exceptions import FieldDoesNotExist, ValidationError
65
from django.db import models
@@ -122,13 +121,9 @@ def setUpTestData(cls):
122121
def test_exact(self):
123122
self.assertCountEqual(Person.objects.filter(pet__weight="3.5"), [self.cat_owners[3]])
124123

125-
# lt/lte don't exclude nonexistent fields. (In these tests, all Dogs are
126-
# also returned since they don't have a weight field.)
127-
@expectedFailure
128124
def test_lt(self):
129125
self.assertCountEqual(Person.objects.filter(pet__weight__lt="3.5"), self.cat_owners[:3])
130126

131-
@expectedFailure
132127
def test_lte(self):
133128
self.assertCountEqual(Person.objects.filter(pet__weight__lte="3.5"), self.cat_owners[:4])
134129

0 commit comments

Comments
 (0)