mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #34606 -- Fixed Right() function with zero length on Oracle and SQLite.
This commit is contained in:
parent
b0a6cc7f57
commit
91be6e1818
1
AUTHORS
1
AUTHORS
@ -545,6 +545,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Justin Michalicek <jmichalicek@gmail.com>
|
Justin Michalicek <jmichalicek@gmail.com>
|
||||||
Justin Myles Holmes <justin@slashrootcafe.com>
|
Justin Myles Holmes <justin@slashrootcafe.com>
|
||||||
Jyrki Pulliainen <jyrki.pulliainen@gmail.com>
|
Jyrki Pulliainen <jyrki.pulliainen@gmail.com>
|
||||||
|
Kacper Wolkiewicz <kac.wolkiewicz@gmail.com>
|
||||||
Kadesarin Sanjek
|
Kadesarin Sanjek
|
||||||
Kapil Bansal <kapilbansal.gbpecdelhi@gmail.com>
|
Kapil Bansal <kapilbansal.gbpecdelhi@gmail.com>
|
||||||
Karderio <karderio@gmail.com>
|
Karderio <karderio@gmail.com>
|
||||||
|
@ -276,7 +276,9 @@ class Right(Left):
|
|||||||
|
|
||||||
def get_substr(self):
|
def get_substr(self):
|
||||||
return Substr(
|
return Substr(
|
||||||
self.source_expressions[0], self.source_expressions[1] * Value(-1)
|
self.source_expressions[0],
|
||||||
|
self.source_expressions[1] * Value(-1),
|
||||||
|
self.source_expressions[1],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
from django.db import connection
|
||||||
from django.db.models import IntegerField, Value
|
from django.db.models import IntegerField, Value
|
||||||
from django.db.models.functions import Lower, Right
|
from django.db.models.functions import Length, Lower, Right
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from ..models import Author
|
from ..models import Author
|
||||||
@ -26,6 +27,21 @@ class RightTests(TestCase):
|
|||||||
with self.assertRaisesMessage(ValueError, "'length' must be greater than 0"):
|
with self.assertRaisesMessage(ValueError, "'length' must be greater than 0"):
|
||||||
Author.objects.annotate(raises=Right("name", 0))
|
Author.objects.annotate(raises=Right("name", 0))
|
||||||
|
|
||||||
|
def test_zero_length(self):
|
||||||
|
Author.objects.create(name="Tom", alias="tom")
|
||||||
|
authors = Author.objects.annotate(
|
||||||
|
name_part=Right("name", Length("name") - Length("alias"))
|
||||||
|
)
|
||||||
|
self.assertQuerySetEqual(
|
||||||
|
authors.order_by("name"),
|
||||||
|
[
|
||||||
|
"mith",
|
||||||
|
"" if connection.features.interprets_empty_strings_as_nulls else None,
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
lambda a: a.name_part,
|
||||||
|
)
|
||||||
|
|
||||||
def test_expressions(self):
|
def test_expressions(self):
|
||||||
authors = Author.objects.annotate(
|
authors = Author.objects.annotate(
|
||||||
name_part=Right("name", Value(3, output_field=IntegerField()))
|
name_part=Right("name", Value(3, output_field=IntegerField()))
|
||||||
|
Loading…
Reference in New Issue
Block a user