mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #20955 -- select_related regression
In cases where the same connection (from model A to model B along the same field) was needed multiple times in a select_related query, the join setup code mistakenly reused an existing join.
This commit is contained in:
parent
c5f768f8cc
commit
8d65b6082c
3 changed files with 49 additions and 4 deletions
|
@ -25,7 +25,7 @@ from .models import (
|
|||
OneToOneCategory, NullableName, ProxyCategory, SingleObject, RelatedObject,
|
||||
ModelA, ModelB, ModelC, ModelD, Responsibility, Job, JobResponsibilities,
|
||||
BaseA, FK1, Identifier, Program, Channel, Page, Paragraph, Chapter, Book,
|
||||
MyObject, Order, OrderItem, SharedConnection)
|
||||
MyObject, Order, OrderItem, SharedConnection, Task, Staff, StaffUser)
|
||||
|
||||
class BaseQuerysetTest(TestCase):
|
||||
def assertValueQuerysetEqual(self, qs, values):
|
||||
|
@ -2992,3 +2992,23 @@ class Ticket14056Tests(TestCase):
|
|||
SharedConnection.objects.order_by('-pointera__connection', 'pk'),
|
||||
expected_ordering, lambda x: x
|
||||
)
|
||||
|
||||
class Ticket20955Tests(TestCase):
|
||||
def test_ticket_20955(self):
|
||||
jack = Staff.objects.create(name='jackstaff')
|
||||
jackstaff = StaffUser.objects.create(staff=jack)
|
||||
jill = Staff.objects.create(name='jillstaff')
|
||||
jillstaff = StaffUser.objects.create(staff=jill)
|
||||
task = Task.objects.create(creator=jackstaff, owner=jillstaff, title="task")
|
||||
task_get = Task.objects.get(pk=task.pk)
|
||||
# Load data so that assertNumQueries doesn't complain about the get
|
||||
# version's queries.
|
||||
task_get.creator.staffuser.staff
|
||||
task_get.owner.staffuser.staff
|
||||
task_select_related = Task.objects.select_related(
|
||||
'creator__staffuser__staff', 'owner__staffuser__staff').get(pk=task.pk)
|
||||
with self.assertNumQueries(0):
|
||||
self.assertEqual(task_select_related.creator.staffuser.staff,
|
||||
task_get.creator.staffuser.staff)
|
||||
self.assertEqual(task_select_related.owner.staffuser.staff,
|
||||
task_get.owner.staffuser.staff)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue