Skip to content

Commit 22c8eb9

Browse files
committed
test triage and rhs json handle.
1 parent a3481ed commit 22c8eb9

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
@@ -251,6 +251,9 @@ def django_test_expected_failures(self):
251251
"expressions_case.tests.CaseExpressionTests.test_order_by_conditional_implicit",
252252
# annotate().filter().count() gives incorrect results.
253253
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_year_exact_lookup",
254+
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_on_subquery",
255+
"model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_count",
256+
"model_fields.test_jsonfield.TestQuerying.test_obj_subquery_lookup",
254257
},
255258
"Count doesn't work in QuerySet.annotate()": {
256259
"annotations.tests.AliasTests.test_alias_annotate_with_aggregation",
@@ -345,6 +348,10 @@ def django_test_expected_failures(self):
345348
"update.tests.SimpleTest.test_empty_update_with_inheritance",
346349
"update.tests.SimpleTest.test_foreign_key_update_with_id",
347350
"update.tests.SimpleTest.test_nonempty_update_with_inheritance",
351+
"model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_key_transform",
352+
"model_fields.test_jsonfield.TestQuerying.test_ordering_by_transform",
353+
"model_fields.test_jsonfield.TestQuerying.test_order_grouping_custom_decoder",
354+
"model_fields.test_jsonfield.TestQuerying.test_join_key_transform_annotation_expression",
348355
},
349356
"Test inspects query for SQL": {
350357
"lookup.tests.LookupTests.test_in_ignore_none",
@@ -359,6 +366,9 @@ def django_test_expected_failures(self):
359366
"timezones.tests.NewDatabaseTests.test_cursor_execute_returns_naive_datetime",
360367
"timezones.tests.NewDatabaseTests.test_cursor_explicit_time_zone",
361368
"timezones.tests.NewDatabaseTests.test_raw_sql",
369+
"model_fields.test_jsonfield.TestQuerying.test_key_transform_raw_expression",
370+
"model_fields.test_jsonfield.TestQuerying.test_key_sql_injection_escape",
371+
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_raw_expression",
362372
},
363373
"Bilateral transform not implemented.": {
364374
"db_functions.tests.FunctionTests.test_func_transform_bilateral",
@@ -416,7 +426,8 @@ def django_test_expected_failures(self):
416426
},
417427
"Mongodb's Null behaviour is different from sql's": {
418428
"model_fields.test_jsonfield.TestQuerying.test_none_key_and_exact_lookup",
419-
# "model_fields.test_jsonfield.TestQuerying.test_isnull_key",
429+
"model_fields.test_jsonfield.TestSaveLoad.test_json_null_different_from_sql_null",
430+
"model_fields.test_jsonfield.TestQuerying.test_none_key",
420431
},
421432
"Pipeline filtering": {"model_fields.test_jsonfield.TestQuerying.test_icontains"},
422433
}

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)