Skip to content

Commit 5fe8ba0

Browse files
committed
test triage and rhs json handle.
1 parent f69df0e commit 5fe8ba0

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

django_mongodb/features.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
177177
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_outerref",
178178
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_trunc_subquery_with_parameters",
179179
"lookup.tests.LookupQueryingTests.test_filter_subquery_lhs",
180+
"model_fields.test_jsonfield.TestQuerying.test_usage_in_subquery",
180181
# ExpressionWrapper not supported.
181182
"annotations.tests.NonAggregateAnnotationTestCase.test_combined_expression_annotation_with_aggregation",
182183
"annotations.tests.NonAggregateAnnotationTestCase.test_combined_f_expression_annotation_with_aggregation",
@@ -209,6 +210,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
209210
# Year lookup + lt/gt crashes: 'dict' object has no attribute 'startswith'
210211
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_year_greaterthan_lookup",
211212
"db_functions.datetime.test_extract_trunc.DateFunctionTests.test_extract_year_lessthan_lookup",
213+
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_on_subquery",
214+
"model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_count",
215+
"model_fields.test_jsonfield.TestQuerying.test_obj_subquery_lookup",
212216
},
213217
"Count doesn't work in QuerySet.annotate()": {
214218
"annotations.tests.AliasTests.test_alias_annotate_with_aggregation",
@@ -286,6 +290,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
286290
"update.tests.SimpleTest.test_empty_update_with_inheritance",
287291
"update.tests.SimpleTest.test_foreign_key_update_with_id",
288292
"update.tests.SimpleTest.test_nonempty_update_with_inheritance",
293+
"model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_key_transform",
294+
"model_fields.test_jsonfield.TestQuerying.test_ordering_by_transform",
295+
"model_fields.test_jsonfield.TestQuerying.test_order_grouping_custom_decoder",
296+
"model_fields.test_jsonfield.TestQuerying.test_join_key_transform_annotation_expression",
289297
},
290298
"Test inspects query for SQL": {
291299
"lookup.tests.LookupTests.test_in_ignore_none",
@@ -300,6 +308,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
300308
"timezones.tests.NewDatabaseTests.test_cursor_execute_returns_naive_datetime",
301309
"timezones.tests.NewDatabaseTests.test_cursor_explicit_time_zone",
302310
"timezones.tests.NewDatabaseTests.test_raw_sql",
311+
"model_fields.test_jsonfield.TestQuerying.test_key_transform_raw_expression",
312+
"model_fields.test_jsonfield.TestQuerying.test_key_sql_injection_escape",
313+
"model_fields.test_jsonfield.TestQuerying.test_nested_key_transform_raw_expression",
303314
},
304315
"Transform not supported.": {
305316
"db_functions.math.test_abs.AbsTests.test_transform",
@@ -377,6 +388,8 @@ class DatabaseFeatures(BaseDatabaseFeatures):
377388
"Mongodb's Null behaviour is different from sql's": {
378389
"model_fields.test_jsonfield.TestQuerying.test_none_key_and_exact_lookup",
379390
# "model_fields.test_jsonfield.TestQuerying.test_isnull_key",
391+
"model_fields.test_jsonfield.TestSaveLoad.test_json_null_different_from_sql_null",
392+
"model_fields.test_jsonfield.TestQuerying.test_none_key",
380393
},
381394
"Pipeline filtering": {"model_fields.test_jsonfield.TestQuerying.test_icontains"},
382395
}

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
@@ -28,7 +28,7 @@ def process_lhs(node, compiler, connection, bare_column_ref=False):
2828
return mql
2929

3030

31-
def process_rhs(node, compiler, connection):
31+
def process_rhs(node, compiler, connection, json_column_ref=False):
3232
rhs = node.rhs
3333
if hasattr(rhs, "as_mql"):
3434
return rhs.as_mql(compiler, connection)
@@ -39,11 +39,11 @@ def process_rhs(node, compiler, connection):
3939
value = value[0]
4040
# Remove percent signs added by PatternLookup.process_rhs() for LIKE
4141
# queries.
42-
if lookup_name in ("startswith", "istartswith"):
42+
if lookup_name in ("startswith", "istartswith") and json_column_ref is False:
4343
value = value[:-1]
44-
elif lookup_name in ("endswith", "iendswith"):
44+
elif lookup_name in ("endswith", "iendswith") and json_column_ref is False:
4545
value = value[1:]
46-
elif lookup_name in ("contains", "icontains"):
46+
elif lookup_name in ("contains", "icontains") and json_column_ref is False:
4747
value = value[1:-1]
4848

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

0 commit comments

Comments
 (0)