@@ -65,14 +65,15 @@ def from_db_value(self, value, expression, connection):
65
65
def json_process_rhs (node , compiler , connection ):
66
66
_ , value = node .process_rhs (compiler , connection )
67
67
68
- # Django's framework transform the [None] into a [null],
69
- # we have to revertit.
70
- if value == ["null" ]:
71
- value = [None ]
72
-
73
68
lookup_name = node .lookup_name
74
69
if lookup_name not in ("in" , "range" ):
75
70
value = value [0 ] if len (value ) > 0 else []
71
+ else :
72
+ result_value = []
73
+ for ind , elem in enumerate (node .rhs ):
74
+ item = f"${ value [ind ]} " if isinstance (elem , KeyTransform ) else value [ind ]
75
+ result_value .append (item )
76
+ value = result_value
76
77
77
78
return value
78
79
@@ -96,24 +97,31 @@ def contained_by(self, compiler, connection): # noqa: ARG001
96
97
97
98
98
99
def json_exact (self , compiler , connection ):
99
- rhs_mql = json_process_rhs (self , compiler , connection )
100
100
lhs_mql = process_lhs (self , compiler , connection )
101
+ rhs_mql = json_process_rhs (self , compiler , connection )
102
+ if rhs_mql == "null" :
103
+ return {"$or" : [{lhs_mql : {"$eq" : None }}, {lhs_mql : {"$exists" : False }}]}
104
+ # return {lhs_mql: {"$eq": None, "$exists": True}}
105
+ # return key_transform_isnull(self, compiler, connection)
101
106
return {lhs_mql : {"$eq" : rhs_mql , "$exists" : True }}
102
107
103
108
104
109
def key_transform_isnull (self , compiler , connection ):
105
110
lhs_mql = process_lhs (self , compiler , connection )
106
111
rhs_mql = json_process_rhs (self , compiler , connection )
107
- if rhs_mql is False :
108
- return {lhs_mql : {"$neq" : None }}
109
- return {"$or" : [{lhs_mql : {"$eq" : None }}, {lhs_mql : {"$exists" : False }}]}
112
+ # if rhs_mql is False:
113
+ # return {lhs_mql: {"$neq": None}}
114
+ # return {"$or": [{lhs_mql: {"$eq": None}}, {lhs_mql: {"$exists": False}}]}
115
+
116
+ # https://code.djangoproject.com/ticket/32252
117
+ return {lhs_mql : {"$exists" : not rhs_mql }}
110
118
111
119
112
120
def key_transform_in (self , compiler , connection ):
113
121
lhs_mql = process_lhs (self , compiler , connection )
114
122
value = json_process_rhs (self , compiler , connection )
115
123
rhs_mql = connection .operators [self .lookup_name ](value )
116
- return {lhs_mql : rhs_mql }
124
+ return {"$expr" : { lhs_mql : rhs_mql } }
117
125
118
126
119
127
def has_key_lookup (self , compiler , connection ):
0 commit comments