mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #28289 -- Fixed crash of RawSQL annotations on inherited model fields.
This commit is contained in:
parent
a9c6ab0356
commit
52545e788d
3 changed files with 33 additions and 0 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue