[2.2.x] Fixed #30672 -- Fixed crash of JSONField/HStoreField key transforms on expressions with params.

Regression in 4f5b58f5cd.

Thanks Florian Apolloner for the report and helping with tests.

Backport of 1f8382d34d from master.
This commit is contained in:
Mariusz Felisiak 2019-08-14 15:25:35 +02:00
parent be4a2a0358
commit 52a7759a49
8 changed files with 68 additions and 3 deletions

View file

@ -2,6 +2,7 @@ import json
from django.core import checks, exceptions, serializers
from django.db import connection
from django.db.models.expressions import RawSQL
from django.forms import Form
from django.test.utils import CaptureQueriesContext, isolate_apps
@ -11,6 +12,7 @@ from .models import HStoreModel, PostgreSQLModel
try:
from django.contrib.postgres import forms
from django.contrib.postgres.fields import HStoreField
from django.contrib.postgres.fields.hstore import KeyTransform
from django.contrib.postgres.validators import KeysValidator
except ImportError:
pass
@ -127,6 +129,13 @@ class TestQuerying(PostgreSQLTestCase):
self.objs[:2]
)
def test_key_transform_raw_expression(self):
expr = RawSQL('%s::hstore', ['x => b, y => c'])
self.assertSequenceEqual(
HStoreModel.objects.filter(field__a=KeyTransform('x', expr)),
self.objs[:2]
)
def test_keys(self):
self.assertSequenceEqual(
HStoreModel.objects.filter(field__keys=['a']),