summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2013-09-24 18:23:02 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2013-10-05 14:52:17 +0300
commited0d720b78c8f1c655ead0057d767a0712f1a6a8 (patch)
treecc63a00c9490493744b9546c93ca4c7e2034c74b
parent20472aa827669d2b83b74e521504e88e18d086a1 (diff)
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.
-rw-r--r--tests/aggregation_regress/models.py11
-rw-r--r--tests/aggregation_regress/tests.py21
2 files changed, 30 insertions, 2 deletions
diff --git a/tests/aggregation_regress/models.py b/tests/aggregation_regress/models.py
index dfef691882..24859f4ce4 100644
--- a/tests/aggregation_regress/models.py
+++ b/tests/aggregation_regress/models.py
@@ -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)
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index a5107d4444..82be5afab2 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -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)