mirror of
https://github.com/django/django.git
synced 2025-08-01 17:42:56 +00:00
[2.2.x] Fixed #30672 -- Fixed crash of JSONField/HStoreField key transforms on expressions with params.
Regression in4f5b58f5cd
. Thanks Florian Apolloner for the report and helping with tests. Backport of1f8382d34d
from master.
This commit is contained in:
parent
be4a2a0358
commit
52a7759a49
8 changed files with 68 additions and 3 deletions
|
@ -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']),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue