Skip to content

Commit 7802896

Browse files
committed
added a string safety-check + allowed unordered lists to be compared
1 parent 0b29263 commit 7802896

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

tests/lookup_/models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33

44
class Book(models.Model):
5-
title = models.CharField(max_length=10, default=None)
6-
isbn = models.CharField(max_length=13, default=None)
7-
8-
class Meta:
9-
ordering = ("title",)
5+
title = models.CharField(max_length=10)
6+
isbn = models.CharField(max_length=13)
107

118
def __str__(self):
129
return self.title or "Title Not Found"

tests/lookup_/tests.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,18 @@ def test_none_filter_nullable_json_exact(self):
9292
[{"$match": {"$and": [{"value": {"$exists": True}}, {"value": None}]}}],
9393
)
9494
self.assertQuerySetEqual(
95-
NullableJSONModel.objects.filter(value=None),
96-
self.null_objs[:-1],
95+
NullableJSONModel.objects.filter(value=None), self.null_objs[:-1], ordered=False
9796
)
9897

9998
def test_none_filter_nullable_json_in(self):
10099
with self.assertNumQueries(1) as ctx:
101-
list(NullableJSONModel.objects.filter(value__in=[None]))
100+
objs = list(NullableJSONModel.objects.filter(value__in=[None]))
102101
self.assertAggregateQuery(
103102
ctx.captured_queries[0]["sql"],
104103
"lookup__nullablejsonmodel",
105104
[{"$match": {"$and": [{"value": {"$exists": True}}, {"value": {"$in": [None]}}]}}],
106105
)
107-
self.assertQuerySetEqual(
108-
NullableJSONModel.objects.filter(value__in=[None]),
109-
self.null_objs[:-1],
110-
)
106+
self.assertQuerySetEqual(objs, self.null_objs[:-1], ordered=False)
111107

112108
def test_none_filter_binary_operator_exact(self):
113109
with self.assertNumQueries(1) as ctx:
@@ -126,7 +122,7 @@ def test_none_filter_binary_operator_exact(self):
126122
}
127123
],
128124
)
129-
self.assertQuerySetEqual(Book.objects.filter(title=None), [])
125+
self.assertQuerySetEqual(Book.objects.filter(title=None), [], ordered=False)
130126

131127
def test_none_filter_binary_operator_in(self):
132128
with self.assertNumQueries(1) as ctx:
@@ -145,4 +141,4 @@ def test_none_filter_binary_operator_in(self):
145141
}
146142
],
147143
)
148-
self.assertQuerySetEqual(Book.objects.filter(title__in=[None]), [])
144+
self.assertQuerySetEqual(Book.objects.filter(title__in=[None]), [], ordered=False)

0 commit comments

Comments
 (0)