mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
[1.8.x] Fixed #25517 -- Made Concat function idempotent on SQLite.
Backport of 6c95b134e9 from master
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import skipUnless
|
||||
|
||||
from django.db import connection
|
||||
from django.db.models import CharField, TextField, Value as V
|
||||
from django.db.models.functions import (
|
||||
Coalesce, Concat, Length, Lower, Substr, Upper,
|
||||
Coalesce, Concat, ConcatPair, Length, Lower, Substr, Upper,
|
||||
)
|
||||
from django.test import TestCase
|
||||
from django.utils import six, timezone
|
||||
@@ -154,6 +157,19 @@ class FunctionTests(TestCase):
|
||||
expected = article.title + ' - ' + article.text
|
||||
self.assertEqual(expected.upper(), article.title_text)
|
||||
|
||||
@skipUnless(connection.vendor == 'sqlite', "sqlite specific implementation detail.")
|
||||
def test_concat_coalesce_idempotent(self):
|
||||
pair = ConcatPair(V('a'), V('b'))
|
||||
# Check nodes counts
|
||||
self.assertEqual(len(list(pair.flatten())), 3)
|
||||
self.assertEqual(len(list(pair.coalesce().flatten())), 7) # + 2 Coalesce + 2 Value()
|
||||
self.assertEqual(len(list(pair.flatten())), 3)
|
||||
|
||||
def test_concat_sql_generation_idempotency(self):
|
||||
qs = Article.objects.annotate(description=Concat('title', V(': '), 'summary'))
|
||||
# Multiple compilations should not alter the generated query.
|
||||
self.assertEqual(str(qs.query), str(qs.all().query))
|
||||
|
||||
def test_lower(self):
|
||||
Author.objects.create(name='John Smith', alias='smithj')
|
||||
Author.objects.create(name='Rhonda')
|
||||
|
||||
Reference in New Issue
Block a user