From ce3c71faf1ff83494193b48a6f99256d0628b2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Fri, 21 Dec 2012 20:07:13 +0200 Subject: [PATCH] Minor improvement to proxy model handling Refs #19385 --- django/db/models/sql/compiler.py | 2 -- django/db/models/sql/query.py | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 16aa031e59..79b5d99452 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -255,8 +255,6 @@ class SQLCompiler(object): result = [] if opts is None: opts = self.query.model._meta - # Skip all proxy to the root proxied model - opts = opts.concrete_model._meta qn = self.quote_name_unless_alias qn2 = self.connection.ops.quote_name aliases = set() diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 43ba519a68..87104f0d13 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -997,8 +997,7 @@ class Query(object): whereas column determination is a later part, and side-effect, of as_sql()). """ - # Skip all proxy models - opts = self.model._meta.concrete_model._meta + opts = self.model._meta root_alias = self.tables[0] seen = {None: root_alias} @@ -1013,7 +1012,8 @@ class Query(object): a parent of 'opts' or if it is None this method is a no-op. The 'alias' is the root alias for starting the join, 'seen' is a dict - of model -> alias of existing joins. + of model -> alias of existing joins. It must also contain a mapping + of None -> some alias. This will be returned in the no-op case. """ if model in seen: return seen[model] @@ -1036,7 +1036,7 @@ class Query(object): connection = (alias, int_opts.db_table, link_field.column, int_opts.pk.column) alias = seen[int_model] = self.join(connection, nullable=False, join_field=link_field) - return alias + return alias or seen[None] def remove_inherited_models(self): """