Skip to content

Commit c8ea0e3

Browse files
committed
test triage and rhs json handle.
1 parent 43d1670 commit c8ea0e3

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

django_mongodb/features.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
205205
"annotations.tests.NonAggregateAnnotationTestCase.test_order_by_annotation",
206206
# annotate().filter().count() gives incorrect results.
207207
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_year_exact_lookup",
208+
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_on_subquery",
209+
"model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_count",
210+
"model_fields.test_jsonfield.TestQuerying.test_obj_subquery_lookup",
208211
},
209212
"Count doesn't work in QuerySet.annotate()": {
210213
"annotations.tests.AliasTests.test_alias_annotate_with_aggregation",
@@ -282,6 +285,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
282285
"update.tests.SimpleTest.test_empty_update_with_inheritance",
283286
"update.tests.SimpleTest.test_foreign_key_update_with_id",
284287
"update.tests.SimpleTest.test_nonempty_update_with_inheritance",
288+
"model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_key_transform",
289+
"model_fields.test_jsonfield.TestQuerying.test_ordering_by_transform",
290+
"model_fields.test_jsonfield.TestQuerying.test_order_grouping_custom_decoder",
291+
"model_fields.test_jsonfield.TestQuerying.test_join_key_transform_annotation_expression",
285292
},
286293
"Test inspects query for SQL": {
287294
"lookup.tests.LookupTests.test_in_ignore_none",
@@ -296,6 +303,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
296303
"timezones.tests.NewDatabaseTests.test_cursor_execute_returns_naive_datetime",
297304
"timezones.tests.NewDatabaseTests.test_cursor_explicit_time_zone",
298305
"timezones.tests.NewDatabaseTests.test_raw_sql",
306+
"model_fields.test_jsonfield.TestQuerying.test_key_transform_raw_expression",
307+
"model_fields.test_jsonfield.TestQuerying.test_key_sql_injection_escape",
308+
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_raw_expression",
299309
},
300310
"Bilateral transform not implemented.": {
301311
"db_functions.tests.FunctionTests.test_func_transform_bilateral",
@@ -353,7 +363,8 @@ class DatabaseFeatures(BaseDatabaseFeatures):
353363
},
354364
"Mongodb's Null behaviour is different from sql's": {
355365
"model_fields.test_jsonfield.TestQuerying.test_none_key_and_exact_lookup",
356-
# "model_fields.test_jsonfield.TestQuerying.test_isnull_key",
366+
"model_fields.test_jsonfield.TestSaveLoad.test_json_null_different_from_sql_null",
367+
"model_fields.test_jsonfield.TestQuerying.test_none_key",
357368
},
358369
"Pipeline filtering": {"model_fields.test_jsonfield.TestQuerying.test_icontains"},
359370
}

django_mongodb/fields/auto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def from_db_value(self, value, expression, connection):
6363

6464

6565
def json_process_rhs(node, compiler, connection):
66+
rhs = node.rhs
67+
if hasattr(rhs, "as_mql"):
68+
return rhs.as_mql(compiler, connection)
6669
_, value = node.process_rhs(compiler, connection)
6770
lookup_name = node.lookup_name
6871
if lookup_name not in ("in", "range"):

django_mongodb/query_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def process_lhs(node, compiler, connection):
2424
return node.lhs.as_mql(compiler, connection)
2525

2626

27-
def process_rhs(node, compiler, connection):
27+
def process_rhs(node, compiler, connection, json_column_ref=False):
2828
rhs = node.rhs
2929
if hasattr(rhs, "as_mql"):
3030
return rhs.as_mql(compiler, connection)
@@ -35,11 +35,11 @@ def process_rhs(node, compiler, connection):
3535
value = value[0]
3636
# Remove percent signs added by PatternLookup.process_rhs() for LIKE
3737
# queries.
38-
if lookup_name in ("startswith", "istartswith"):
38+
if lookup_name in ("startswith", "istartswith") and json_column_ref is False:
3939
value = value[:-1]
40-
elif lookup_name in ("endswith", "iendswith"):
40+
elif lookup_name in ("endswith", "iendswith") and json_column_ref is False:
4141
value = value[1:]
42-
elif lookup_name in ("contains", "icontains"):
42+
elif lookup_name in ("contains", "icontains") and json_column_ref is False:
4343
value = value[1:-1]
4444

4545
return connection.ops.prep_lookup_value(value, node.lhs.output_field, node.lookup_name)

0 commit comments

Comments
 (0)