Fixed #21203 -- resolve_columns fields misalignment
In queries using .defer() together with .select_related() the values and fields arguments didn't align properly for resolve_columns().
This commit is contained in:
parent
0d02c54299
commit
bf13c75c0d
|
@ -713,9 +713,8 @@ class SQLCompiler(object):
|
||||||
# into `resolve_columns` because it wasn't selected.
|
# into `resolve_columns` because it wasn't selected.
|
||||||
only_load = self.deferred_to_columns()
|
only_load = self.deferred_to_columns()
|
||||||
if only_load:
|
if only_load:
|
||||||
db_table = self.query.get_meta().db_table
|
fields = [f for f in fields if f.model._meta.db_table not in only_load or
|
||||||
fields = [f for f in fields if db_table in only_load and
|
f.column in only_load[f.model._meta.db_table]]
|
||||||
f.column in only_load[db_table]]
|
|
||||||
if has_aggregate_select:
|
if has_aggregate_select:
|
||||||
# pad None in to fields for aggregates
|
# pad None in to fields for aggregates
|
||||||
fields = fields[:aggregate_start] + [
|
fields = fields[:aggregate_start] + [
|
||||||
|
|
|
@ -535,3 +535,12 @@ class StaffUser(BaseUser):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.staff
|
return self.staff
|
||||||
|
|
||||||
|
class Ticket21203Parent(models.Model):
|
||||||
|
parentid = models.AutoField(primary_key=True)
|
||||||
|
parent_bool = models.BooleanField(default=True)
|
||||||
|
created = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
class Ticket21203Child(models.Model):
|
||||||
|
childid = models.AutoField(primary_key=True)
|
||||||
|
parent = models.ForeignKey(Ticket21203Parent)
|
||||||
|
|
|
@ -26,7 +26,7 @@ from .models import (
|
||||||
ModelA, ModelB, ModelC, ModelD, Responsibility, Job, JobResponsibilities,
|
ModelA, ModelB, ModelC, ModelD, Responsibility, Job, JobResponsibilities,
|
||||||
BaseA, FK1, Identifier, Program, Channel, Page, Paragraph, Chapter, Book,
|
BaseA, FK1, Identifier, Program, Channel, Page, Paragraph, Chapter, Book,
|
||||||
MyObject, Order, OrderItem, SharedConnection, Task, Staff, StaffUser,
|
MyObject, Order, OrderItem, SharedConnection, Task, Staff, StaffUser,
|
||||||
CategoryRelationship)
|
CategoryRelationship, Ticket21203Parent, Ticket21203Child)
|
||||||
|
|
||||||
class BaseQuerysetTest(TestCase):
|
class BaseQuerysetTest(TestCase):
|
||||||
def assertValueQuerysetEqual(self, qs, values):
|
def assertValueQuerysetEqual(self, qs, values):
|
||||||
|
@ -3071,3 +3071,11 @@ class Ticket20955Tests(TestCase):
|
||||||
task_get.creator.staffuser.staff)
|
task_get.creator.staffuser.staff)
|
||||||
self.assertEqual(task_select_related.owner.staffuser.staff,
|
self.assertEqual(task_select_related.owner.staffuser.staff,
|
||||||
task_get.owner.staffuser.staff)
|
task_get.owner.staffuser.staff)
|
||||||
|
|
||||||
|
class Ticket21203Tests(TestCase):
|
||||||
|
def test_ticket_21203(self):
|
||||||
|
p = Ticket21203Parent.objects.create(parent_bool=True)
|
||||||
|
c = Ticket21203Child.objects.create(parent=p)
|
||||||
|
qs = Ticket21203Child.objects.select_related('parent').defer('parent__created')
|
||||||
|
self.assertQuerysetEqual(qs, [c], lambda x: x)
|
||||||
|
self.assertIs(qs[0].parent.parent_bool, True)
|
||||||
|
|
Loading…
Reference in New Issue