mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #29251 -- Added bytes to str conversion in LPad/RPad database functions on MySQL.
Thanks Tim Graham for the review.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from django.db.models import Value
|
||||
from django.db.models.functions import LPad, RPad
|
||||
from django.db.models import CharField, Value
|
||||
from django.db.models.functions import Length, LPad, RPad
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Author
|
||||
@@ -32,3 +32,13 @@ class PadTests(TestCase):
|
||||
with self.subTest(function=function):
|
||||
with self.assertRaisesMessage(ValueError, "'length' must be greater or equal to 0."):
|
||||
function('name', -1)
|
||||
|
||||
def test_combined_with_length(self):
|
||||
Author.objects.create(name='Rhonda', alias='john_smith')
|
||||
Author.objects.create(name='♥♣♠', alias='bytes')
|
||||
authors = Author.objects.annotate(filled=LPad('name', Length('alias'), output_field=CharField()))
|
||||
self.assertQuerysetEqual(
|
||||
authors.order_by('alias'),
|
||||
[' ♥♣♠', ' Rhonda'],
|
||||
lambda a: a.filled,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user