summaryrefslogtreecommitdiff
path: root/tests/modeltests/defer
diff options
context:
space:
mode:
Diffstat (limited to 'tests/modeltests/defer')
-rw-r--r--tests/modeltests/defer/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/modeltests/defer/tests.py b/tests/modeltests/defer/tests.py
index 09138293af..eb09162b01 100644
--- a/tests/modeltests/defer/tests.py
+++ b/tests/modeltests/defer/tests.py
@@ -158,3 +158,18 @@ class DeferTests(TestCase):
self.assert_delayed(child, 1)
self.assertEqual(child.name, 'p1')
self.assertEqual(child.value, 'xx')
+
+ def test_defer_inheritance_pk_chaining(self):
+ """
+ When an inherited model is fetched from the DB, its PK is also fetched.
+ When getting the PK of the parent model it is useful to use the already
+ fetched parent model PK if it happens to be available. Tests that this
+ is done.
+ """
+ s1 = Secondary.objects.create(first="x1", second="y1")
+ bc = BigChild.objects.create(name="b1", value="foo", related=s1,
+ other="bar")
+ bc_deferred = BigChild.objects.only('name').get(pk=bc.pk)
+ with self.assertNumQueries(0):
+ bc_deferred.id
+ self.assertEqual(bc_deferred.pk, bc_deferred.id)