summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jwalls@element84.com>2023-04-10 16:30:08 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-04-11 05:56:47 +0200
commitc3d7a71f836f7cfe8fa90dd9ae95b37b660d5aae (patch)
treee08196e7d6a875817129c37fbd9cdeab86a82640
parent3b4728310a7a64f8fcc548163b0aa5f98a5c78f5 (diff)
Fixed #34480 -- Fixed crash of annotations with Chr().
-rw-r--r--django/db/models/functions/text.py1
-rw-r--r--tests/db_functions/text/test_chr.py12
2 files changed, 12 insertions, 1 deletions
diff --git a/django/db/models/functions/text.py b/django/db/models/functions/text.py
index 8715e86898..34421eb15d 100644
--- a/django/db/models/functions/text.py
+++ b/django/db/models/functions/text.py
@@ -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(
diff --git a/tests/db_functions/text/test_chr.py b/tests/db_functions/text/test_chr.py
index 7a55994096..fe1aea3f2c 100644
--- a/tests/db_functions/text/test_chr.py
+++ b/tests/db_functions/text/test_chr.py
@@ -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],
+ )