diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-13 08:42:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-13 08:42:17 +0200 |
| commit | c19ad2da4b573431843e5cead77f4139e29c77a0 (patch) | |
| tree | e8a311c6a7fb35c8130bf219c9f5ed203350fb84 /tests/postgres_tests | |
| parent | efa1908f662c19038a944129c81462485c4a9fe8 (diff) | |
Fixed #30704 -- Fixed crash of JSONField nested key and index transforms on expressions with params.
Thanks Florian Apolloner for the report and helping with tests.
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/test_json.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py index 1360bc85dc..d00f97c36e 100644 --- a/tests/postgres_tests/test_json.py +++ b/tests/postgres_tests/test_json.py @@ -6,7 +6,9 @@ from decimal import Decimal from django.core import checks, exceptions, serializers from django.core.serializers.json import DjangoJSONEncoder from django.db import connection -from django.db.models import Count, Q +from django.db.models import Count, F, Q +from django.db.models.expressions import RawSQL +from django.db.models.functions import Cast from django.forms import CharField, Form, widgets from django.test.utils import CaptureQueriesContext, isolate_apps from django.utils.html import escape @@ -186,6 +188,23 @@ class TestQuerying(PostgreSQLTestCase): operator.itemgetter('key', 'count'), ) + def test_nested_key_transform_raw_expression(self): + expr = RawSQL('%s::jsonb', ['{"x": {"y": "bar"}}']) + self.assertSequenceEqual( + JSONModel.objects.filter(field__foo=KeyTransform('y', KeyTransform('x', expr))), + [self.objs[-1]], + ) + + def test_nested_key_transform_expression(self): + self.assertSequenceEqual( + JSONModel.objects.filter(field__d__0__isnull=False).annotate( + key=KeyTransform('d', 'field'), + chain=KeyTransform('f', KeyTransform('1', 'key')), + expr=KeyTransform('f', KeyTransform('1', Cast('key', JSONField()))), + ).filter(chain=F('expr')), + [self.objs[8]], + ) + def test_deep_values(self): query = JSONModel.objects.values_list('field__k__l') self.assertSequenceEqual( |
