1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #26511 -- Fixed json.KeyTextTransform() on MySQL/MariaDB.

This commit is contained in:
Mariusz Felisiak
2022-08-18 21:02:29 +02:00
committed by GitHub
parent bd36023100
commit e9fd2b5724
2 changed files with 25 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ from django import forms
from django.core import checks, exceptions
from django.db import NotSupportedError, connections, router
from django.db.models import lookups
from django.db.models.fields import TextField
from django.db.models.lookups import PostgresOperatorLookup, Transform
from django.utils.translation import gettext_lazy as _
@@ -366,6 +367,17 @@ class KeyTransform(Transform):
class KeyTextTransform(KeyTransform):
postgres_operator = "->>"
postgres_nested_operator = "#>>"
output_field = TextField()
def as_mysql(self, compiler, connection):
if connection.mysql_is_mariadb:
# MariaDB doesn't support -> and ->> operators (see MDEV-13594).
sql, params = super().as_mysql(compiler, connection)
return "JSON_UNQUOTE(%s)" % sql, params
else:
lhs, params, key_transforms = self.preprocess_lhs(compiler, connection)
json_path = compile_json_path(key_transforms)
return "(%s ->> %%s)" % lhs, tuple(params) + (json_path,)
class KeyTransformTextLookupMixin: