Fixed #21413 -- resolve_columns fields misalignment
This commit is contained in:
parent
9cc3371a0f
commit
9918c11114
|
@ -133,7 +133,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
|
||||||
if table in only_load and field.column not in only_load[table]:
|
if table in only_load and field.column not in only_load[table]:
|
||||||
continue
|
continue
|
||||||
if as_pairs:
|
if as_pairs:
|
||||||
result.append((alias, field.column))
|
result.append((alias, field))
|
||||||
aliases.add(alias)
|
aliases.add(alias)
|
||||||
continue
|
continue
|
||||||
# This part of the function is customized for GeoQuery. We
|
# This part of the function is customized for GeoQuery. We
|
||||||
|
|
|
@ -295,7 +295,7 @@ class SQLCompiler(object):
|
||||||
if table in only_load and column not in only_load[table]:
|
if table in only_load and column not in only_load[table]:
|
||||||
continue
|
continue
|
||||||
if as_pairs:
|
if as_pairs:
|
||||||
result.append((alias, column))
|
result.append((alias, field))
|
||||||
aliases.add(alias)
|
aliases.add(alias)
|
||||||
continue
|
continue
|
||||||
if with_aliases and column in col_aliases:
|
if with_aliases and column in col_aliases:
|
||||||
|
@ -625,10 +625,10 @@ class SQLCompiler(object):
|
||||||
_, _, _, joins, _ = self.query.setup_joins(
|
_, _, _, joins, _ = self.query.setup_joins(
|
||||||
[f.name], opts, root_alias)
|
[f.name], opts, root_alias)
|
||||||
alias = joins[-1]
|
alias = joins[-1]
|
||||||
columns, aliases = self.get_default_columns(start_alias=alias,
|
columns, _ = self.get_default_columns(start_alias=alias,
|
||||||
opts=f.rel.to._meta, as_pairs=True)
|
opts=f.rel.to._meta, as_pairs=True)
|
||||||
self.query.related_select_cols.extend(
|
self.query.related_select_cols.extend(
|
||||||
SelectInfo(col, field) for col, field in zip(columns, f.rel.to._meta.concrete_fields))
|
SelectInfo((col[0], col[1].column), col[1]) for col in columns)
|
||||||
if restricted:
|
if restricted:
|
||||||
next = requested.get(f.name, {})
|
next = requested.get(f.name, {})
|
||||||
else:
|
else:
|
||||||
|
@ -652,11 +652,10 @@ class SQLCompiler(object):
|
||||||
alias = joins[-1]
|
alias = joins[-1]
|
||||||
from_parent = (opts.model if issubclass(model, opts.model)
|
from_parent = (opts.model if issubclass(model, opts.model)
|
||||||
else None)
|
else None)
|
||||||
columns, aliases = self.get_default_columns(start_alias=alias,
|
columns, _ = self.get_default_columns(start_alias=alias,
|
||||||
opts=model._meta, as_pairs=True, from_parent=from_parent)
|
opts=model._meta, as_pairs=True, from_parent=from_parent)
|
||||||
self.query.related_select_cols.extend(
|
self.query.related_select_cols.extend(
|
||||||
SelectInfo(col, field) for col, field
|
SelectInfo((col[0], col[1].column), col[1]) for col in columns)
|
||||||
in zip(columns, model._meta.concrete_fields))
|
|
||||||
next = requested.get(f.related_query_name(), {})
|
next = requested.get(f.related_query_name(), {})
|
||||||
self.fill_related_selections(model._meta, alias, cur_depth + 1,
|
self.fill_related_selections(model._meta, alias, cur_depth + 1,
|
||||||
next, restricted)
|
next, restricted)
|
||||||
|
@ -699,8 +698,10 @@ class SQLCompiler(object):
|
||||||
# found in get_columns(). It would be nice to clean this up.
|
# found in get_columns(). It would be nice to clean this up.
|
||||||
if self.query.select:
|
if self.query.select:
|
||||||
fields = [f.field for f in self.query.select]
|
fields = [f.field for f in self.query.select]
|
||||||
else:
|
elif self.query.default_cols:
|
||||||
fields = self.query.get_meta().concrete_fields
|
fields = self.query.get_meta().concrete_fields
|
||||||
|
else:
|
||||||
|
fields = []
|
||||||
fields = fields + [f.field for f in self.query.related_select_cols]
|
fields = fields + [f.field for f in self.query.related_select_cols]
|
||||||
|
|
||||||
# If the field was deferred, exclude it from being passed
|
# If the field was deferred, exclude it from being passed
|
||||||
|
|
|
@ -460,3 +460,9 @@ class ModelInheritanceTest(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
Senator.objects.get(pk=senator.pk)
|
Senator.objects.get(pk=senator.pk)
|
||||||
|
|
||||||
|
def test_inheritance_resolve_columns(self):
|
||||||
|
Restaurant.objects.create(name='Bobs Cafe', address="Somewhere",
|
||||||
|
serves_pizza=True, serves_hot_dogs=True)
|
||||||
|
p = Place.objects.all().select_related('restaurant')[0]
|
||||||
|
self.assertIsInstance(p.restaurant.serves_pizza, bool)
|
||||||
|
|
Loading…
Reference in New Issue