diff options
| author | Kacper Wolkiewicz <45897171+wolkiewiczk@users.noreply.github.com> | 2023-05-31 12:57:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-31 11:57:40 +0100 |
| commit | 91be6e1818c3cb70890608491eea79e984f98ede (patch) | |
| tree | e98ac3fd5b571a011ad6bd81f96208575ea8caa8 /tests/db_functions | |
| parent | b0a6cc7f5738d6b959faf10354b772338f611fd9 (diff) | |
Fixed #34606 -- Fixed Right() function with zero length on Oracle and SQLite.
Diffstat (limited to 'tests/db_functions')
| -rw-r--r-- | tests/db_functions/text/test_right.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/db_functions/text/test_right.py b/tests/db_functions/text/test_right.py index 126f1583a5..93d929f9e0 100644 --- a/tests/db_functions/text/test_right.py +++ b/tests/db_functions/text/test_right.py @@ -1,5 +1,6 @@ +from django.db import connection 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 ..models import Author @@ -26,6 +27,21 @@ class RightTests(TestCase): with self.assertRaisesMessage(ValueError, "'length' must be greater than 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): authors = Author.objects.annotate( name_part=Right("name", Value(3, output_field=IntegerField())) |
