diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-14 15:25:35 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-14 15:37:01 +0200 |
| commit | 968b9af9b7f7e49af17fc82de5a2de9a91b86e44 (patch) | |
| tree | e4eb30ff145130808f4f0e709d6b38d43624b258 /tests/postgres_tests/test_json.py | |
| parent | 46c2856543f97f41f520426483413eb8b64c878b (diff) | |
[2.1.x] Fixed #30672 -- Fixed crash of JSONField/HStoreField key transforms on expressions with params.
Regression in 4f5b58f5cd3c57fee9972ab074f8dc6895d8f387.
Thanks Florian Apolloner for the report and helping with tests.
Backport of 1f8382d34d54061eddc41df6994e20ee38c60907 from master.
Diffstat (limited to 'tests/postgres_tests/test_json.py')
| -rw-r--r-- | tests/postgres_tests/test_json.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py index e58c7a2e7f..01215aa954 100644 --- a/tests/postgres_tests/test_json.py +++ b/tests/postgres_tests/test_json.py @@ -5,7 +5,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 Q +from django.db.models import 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 @@ -16,6 +18,7 @@ from .models import JSONModel, PostgreSQLModel try: from django.contrib.postgres import forms from django.contrib.postgres.fields import JSONField + from django.contrib.postgres.fields.jsonb import KeyTransform except ImportError: pass @@ -154,6 +157,23 @@ class TestQuerying(PostgreSQLTestCase): query = JSONModel.objects.filter(field__name__isnull=False).order_by('field__ord') self.assertSequenceEqual(query, [objs[4], objs[2], objs[3], objs[1], objs[0]]) + def test_key_transform_raw_expression(self): + expr = RawSQL('%s::jsonb', ['{"x": "bar"}']) + self.assertSequenceEqual( + JSONModel.objects.filter(field__foo=KeyTransform('x', expr)), + [self.objs[-1]], + ) + + def test_key_transform_expression(self): + self.assertSequenceEqual( + JSONModel.objects.filter(field__d__0__isnull=False).annotate( + key=KeyTransform('d', 'field'), + chain=KeyTransform('0', 'key'), + expr=KeyTransform('0', 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( |
