Fixed #21150 -- select_related + annotate join promotion failure
Added tests for a .annotate().select_related() join promotion failure. This happened to work on master but was currently untested.
This commit is contained in:
parent
20472aa827
commit
ed0d720b78
|
@ -87,3 +87,14 @@ class HardbackBook(Book):
|
|||
|
||||
def __str__(self):
|
||||
return "%s (hardback): %s" % (self.name, self.weight)
|
||||
|
||||
# Models for ticket #21150
|
||||
class Alfa(models.Model):
|
||||
pass
|
||||
|
||||
class Bravo(models.Model):
|
||||
pass
|
||||
|
||||
class Charlie(models.Model):
|
||||
alfa = models.ForeignKey(Alfa, null=True)
|
||||
bravo = models.ForeignKey(Bravo, null=True)
|
||||
|
|
|
@ -12,8 +12,9 @@ from django.test import TestCase, skipUnlessDBFeature
|
|||
from django.test.utils import Approximate
|
||||
from django.utils import six
|
||||
|
||||
from .models import (Author, Book, Publisher, Clues, Entries, HardbackBook,
|
||||
ItemTag, WithManualPK)
|
||||
from .models import (
|
||||
Author, Book, Publisher, Clues, Entries, HardbackBook, ItemTag,
|
||||
WithManualPK, Alfa, Bravo, Charlie)
|
||||
|
||||
|
||||
class AggregationTests(TestCase):
|
||||
|
@ -1135,3 +1136,19 @@ class AggregationTests(TestCase):
|
|||
'select__sum': 10,
|
||||
'select__avg': Approximate(1.666, places=2),
|
||||
})
|
||||
|
||||
def test_ticket_21150(self):
|
||||
b = Bravo.objects.create()
|
||||
c = Charlie.objects.create(bravo=b)
|
||||
qs = Charlie.objects.select_related('alfa').annotate(Count('bravo__charlie'))
|
||||
self.assertQuerysetEqual(
|
||||
qs, [c], lambda x: x)
|
||||
self.assertIs(qs[0].alfa, None)
|
||||
a = Alfa.objects.create()
|
||||
c.alfa = a
|
||||
c.save()
|
||||
# Force re-evaluation
|
||||
qs = qs.all()
|
||||
self.assertQuerysetEqual(
|
||||
qs, [c], lambda x: x)
|
||||
self.assertEqual(qs[0].alfa, a)
|
||||
|
|
Loading…
Reference in New Issue