mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
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.
This commit is contained in:
@@ -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']),
|
||||
|
||||
Reference in New Issue
Block a user