File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
tests/expression_converter_ Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ from django .db import models
2+
3+
4+ class NullableJSONModel (models .Model ):
5+ value = models .JSONField (blank = True , null = True )
6+
7+ class Meta :
8+ required_db_features = {"supports_json_field" }
9+
10+
11+ class Tag (models .Model ):
12+ name = models .CharField (max_length = 10 )
13+
14+ def __str__ (self ):
15+ return self .name
Original file line number Diff line number Diff line change 1+ from django .test import TestCase
2+
3+ from django_mongodb_backend .test import MongoTestCaseMixin
4+
5+ from .models import NullableJSONModel , Tag
6+
7+
8+ class MQLTests (MongoTestCaseMixin , TestCase ):
9+ def test_none_filter_nullable_json (self ):
10+ with self .assertNumQueries (1 ) as ctx :
11+ list (NullableJSONModel .objects .filter (value = None ))
12+ self .assertAggregateQuery (
13+ ctx .captured_queries [0 ]["sql" ],
14+ "queries__nullablejsonmodel" ,
15+ [{"$match" : {"$and" : [{"$exists" : False }, {"value" : None }]}}],
16+ )
17+
18+ def test_none_filter (self ):
19+ with self .assertNumQueries (1 ) as ctx :
20+ list (Tag .objects .filter (name = None ))
21+ self .assertAggregateQuery (
22+ ctx .captured_queries [0 ]["sql" ],
23+ "queries__nullablejsonmodel" ,
24+ [
25+ {
26+ "$match" : {
27+ "$or" : [
28+ {"$and" : [{"name" : {"$exists" : True }}, {"name" : None }]},
29+ {"$expr" : {"$eq" : [{"$type" : "$name" }, "missing" ]}},
30+ ]
31+ }
32+ }
33+ ],
34+ )
You can’t perform that action at this time.
0 commit comments