Fixed #34554 -- Fixed Reverse(Value(…)) crash on Oracle.

This commit is contained in:
Mariusz Felisiak 2023-05-10 17:22:45 +02:00 committed by GitHub
parent c494c6974d
commit 6e32d1fa1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -257,7 +257,7 @@ class Reverse(Transform):
def as_oracle(self, compiler, connection, **extra_context): def as_oracle(self, compiler, connection, **extra_context):
# REVERSE in Oracle is undocumented and doesn't support multi-byte # REVERSE in Oracle is undocumented and doesn't support multi-byte
# strings. Use a special subquery instead. # strings. Use a special subquery instead.
return super().as_sql( sql, params = super().as_sql(
compiler, compiler,
connection, connection,
template=( template=(
@ -268,6 +268,7 @@ class Reverse(Transform):
), ),
**extra_context, **extra_context,
) )
return sql, params * 3
class Right(Left): class Right(Left):

View File

@ -1,5 +1,5 @@
from django.db import connection from django.db import connection
from django.db.models import CharField from django.db.models import CharField, Value
from django.db.models.functions import Length, Reverse, Trim from django.db.models.functions import Length, Reverse, Trim
from django.test import TestCase from django.test import TestCase
from django.test.utils import register_lookup from django.test.utils import register_lookup
@ -24,15 +24,18 @@ class ReverseTests(TestCase):
) )
def test_basic(self): def test_basic(self):
authors = Author.objects.annotate(backward=Reverse("name")) authors = Author.objects.annotate(
backward=Reverse("name"),
constant=Reverse(Value("static string")),
)
self.assertQuerySetEqual( self.assertQuerySetEqual(
authors, authors,
[ [
("John Smith", "htimS nhoJ"), ("John Smith", "htimS nhoJ", "gnirts citats"),
("Élena Jordan", "nadroJ anelÉ"), ("Élena Jordan", "nadroJ anelÉ", "gnirts citats"),
("パイソン", "ンソイパ"), ("パイソン", "ンソイパ", "gnirts citats"),
], ],
lambda a: (a.name, a.backward), lambda a: (a.name, a.backward, a.constant),
ordered=False, ordered=False,
) )