summaryrefslogtreecommitdiff
path: root/tests/annotations
diff options
context:
space:
mode:
authorcan <cansarigol@derinbilgi.com.tr>2019-07-10 15:07:48 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-11 08:27:15 +0200
commit52545e788d664040abf4f1a5d77cdfc61152ffca (patch)
tree72726e1a7c7343ad3ebadf97dfa5a7be1f8adc50 /tests/annotations
parenta9c6ab03560424ed7dff24849c8ddaa3e1eae62e (diff)
downloaddjango-52545e788d664040abf4f1a5d77cdfc61152ffca.tar.gz
Fixed #28289 -- Fixed crash of RawSQL annotations on inherited model fields.
Diffstat (limited to 'tests/annotations')
-rw-r--r--tests/annotations/models.py1
-rw-r--r--tests/annotations/tests.py22
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/annotations/models.py b/tests/annotations/models.py
index 4aeda3c093..cd3d6ddb87 100644
--- a/tests/annotations/models.py
+++ b/tests/annotations/models.py
@@ -38,6 +38,7 @@ class Store(models.Model):
books = models.ManyToManyField(Book)
original_opening = models.DateTimeField()
friday_night_closing = models.TimeField()
+ area = models.IntegerField(null=True, db_column='surface')
def __str__(self):
return self.name
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index af13915312..c39e8d3fbe 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -405,6 +405,28 @@ class NonAggregateAnnotationTestCase(TestCase):
lambda a: (a['age'], a['age_count'])
)
+ def test_raw_sql_with_inherited_field(self):
+ DepartmentStore.objects.create(
+ name='Angus & Robinson',
+ original_opening=datetime.date(2014, 3, 8),
+ friday_night_closing=datetime.time(21),
+ chain='Westfield',
+ area=123,
+ )
+ tests = (
+ ('name', 'Angus & Robinson'),
+ ('surface', 123),
+ ("case when name='Angus & Robinson' then chain else name end", 'Westfield'),
+ )
+ for sql, expected_result in tests:
+ with self.subTest(sql=sql):
+ self.assertSequenceEqual(
+ DepartmentStore.objects.annotate(
+ annotation=RawSQL(sql, ()),
+ ).values_list('annotation', flat=True),
+ [expected_result],
+ )
+
def test_annotate_exists(self):
authors = Author.objects.annotate(c=Count('id')).filter(c__gt=1)
self.assertFalse(authors.exists())