mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #10733 -- select_related().only() failure
The bug was reported pre 1.1, and somewhere along the way it has been fixed. So, this is tests only addition.
This commit is contained in:
parent
32e40bbe71
commit
8d4b1629d4
2 changed files with 35 additions and 1 deletions
|
@ -5,7 +5,7 @@ from django.utils import six
|
|||
|
||||
from .models import (Building, Child, Device, Port, Item, Country, Connection,
|
||||
ClientStatus, State, Client, SpecialClient, TUser, Person, Student,
|
||||
Organizer, Class, Enrollment, Hen, Chick)
|
||||
Organizer, Class, Enrollment, Hen, Chick, Base, A, B, C)
|
||||
|
||||
|
||||
class SelectRelatedRegressTests(TestCase):
|
||||
|
@ -173,3 +173,19 @@ class SelectRelatedRegressTests(TestCase):
|
|||
|
||||
self.assertEqual(Chick.objects.all()[0].mother.name, 'Hen')
|
||||
self.assertEqual(Chick.objects.select_related()[0].mother.name, 'Hen')
|
||||
|
||||
def test_ticket_10733(self):
|
||||
a = A.objects.create(name='a', lots_of_text='lots_of_text_a', a_field='a_field')
|
||||
b = B.objects.create(name='b', lots_of_text='lots_of_text_b', b_field='b_field')
|
||||
c = C.objects.create(name='c', lots_of_text='lots_of_text_c', is_published=True,
|
||||
c_a=a, c_b=b)
|
||||
results = C.objects.all().only('name', 'lots_of_text', 'c_a', 'c_b', 'c_b__lots_of_text',
|
||||
'c_a__name', 'c_b__name').select_related()
|
||||
self.assertQuerysetEqual(results, [c], lambda x: x)
|
||||
with self.assertNumQueries(0):
|
||||
qs_c = results[0]
|
||||
self.assertEqual(qs_c.name, 'c')
|
||||
self.assertEqual(qs_c.lots_of_text, 'lots_of_text_c')
|
||||
self.assertEqual(qs_c.c_b.lots_of_text, 'lots_of_text_b')
|
||||
self.assertEqual(qs_c.c_a.name, 'a')
|
||||
self.assertEqual(qs_c.c_b.name, 'b')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue