1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #14056 -- Made sure LEFT JOIN aren't trimmed in ORDER BY

If LEFT JOINs are required for correct results, then trimming the join
can lead to incorrect results. Consider case:

TBL A: ID | TBL B: ID  A_ID
       1           1   1
       2
Now A.order_by('b__a') did use a join to B, and B's a_id column. This
was seen to contain the same value as A's id, and so the join was
trimmed. But this wasn't correct as the join is LEFT JOIN, and for row
A.id = 2 the B.a_id column is NULL.
This commit is contained in:
Anssi Kääriäinen
2013-08-20 10:32:18 +03:00
parent b53ed351b3
commit 905409855c
2 changed files with 24 additions and 35 deletions

View File

@@ -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)
MyObject, Order, OrderItem, SharedConnection)
class BaseQuerysetTest(TestCase):
def assertValueQuerysetEqual(self, qs, values):
@@ -2977,3 +2977,14 @@ class RelatedLookupTypeTests(TestCase):
self.assertQuerysetEqual(
ObjectB.objects.filter(objecta__in=[wrong_type]),
[ob], lambda x: x)
class Ticket14056Tests(TestCase):
def test_ticket_14056(self):
s1 = SharedConnection.objects.create(data='s1')
s2 = SharedConnection.objects.create(data='s2')
s3 = SharedConnection.objects.create(data='s3')
PointerA.objects.create(connection=s2)
self.assertQuerysetEqual(
SharedConnection.objects.order_by('pointera__connection', 'pk'),
[s1, s3, s2], lambda x: x
)