1
0
mirror of https://github.com/django/django.git synced 2025-01-22 00:02:15 +00:00

Fixed #34480 -- Fixed crash of annotations with Chr().

This commit is contained in:
Jacob Walls 2023-04-10 16:30:08 -04:00 committed by Mariusz Felisiak
parent 3b4728310a
commit c3d7a71f83
2 changed files with 12 additions and 1 deletions

View File

@ -42,6 +42,7 @@ class PostgreSQLSHAMixin:
class Chr(Transform):
function = "CHR"
lookup_name = "chr"
output_field = CharField()
def as_mysql(self, compiler, connection, **extra_context):
return super().as_sql(

View File

@ -1,4 +1,4 @@
from django.db.models import IntegerField
from django.db.models import F, IntegerField
from django.db.models.functions import Chr, Left, Ord
from django.test import TestCase
from django.test.utils import register_lookup
@ -37,3 +37,13 @@ class ChrTests(TestCase):
authors.exclude(name_code_point__chr=Chr(ord("J"))),
[self.elena, self.rhonda],
)
def test_annotate(self):
authors = Author.objects.annotate(
first_initial=Left("name", 1),
initial_chr=Chr(ord("J")),
)
self.assertSequenceEqual(
authors.filter(first_initial=F("initial_chr")),
[self.john],
)