mirror of
https://github.com/django/django.git
synced 2025-06-02 10:09:12 +00:00
Fixed #34480 -- Fixed crash of annotations with Chr().
This commit is contained in:
parent
3b4728310a
commit
c3d7a71f83
@ -42,6 +42,7 @@ class PostgreSQLSHAMixin:
|
|||||||
class Chr(Transform):
|
class Chr(Transform):
|
||||||
function = "CHR"
|
function = "CHR"
|
||||||
lookup_name = "chr"
|
lookup_name = "chr"
|
||||||
|
output_field = CharField()
|
||||||
|
|
||||||
def as_mysql(self, compiler, connection, **extra_context):
|
def as_mysql(self, compiler, connection, **extra_context):
|
||||||
return super().as_sql(
|
return super().as_sql(
|
||||||
|
@ -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.db.models.functions import Chr, Left, Ord
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import register_lookup
|
from django.test.utils import register_lookup
|
||||||
@ -37,3 +37,13 @@ class ChrTests(TestCase):
|
|||||||
authors.exclude(name_code_point__chr=Chr(ord("J"))),
|
authors.exclude(name_code_point__chr=Chr(ord("J"))),
|
||||||
[self.elena, self.rhonda],
|
[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],
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user