Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit ed0d720b78c8f1c655ead0057d767a0712f1a6a8 1 parent 20472aa
Anssi Kääriäinen akaariai authored
11 tests/aggregation_regress/models.py
View
@@ -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)
21 tests/aggregation_regress/tests.py
View
@@ -12,8 +12,9 @@
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 @@ def test_annotate_reserved_word(self):
'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)
Please sign in to comment.
Something went wrong with that request. Please try again.