diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2012-05-09 20:33:31 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-05-09 20:33:31 +0300 |
| commit | c2e1ecb4b136016ab2996712aa0583fd91657bc9 (patch) | |
| tree | 1a263f7a93ac5c2887b7ad2425a37b8dc191fecc /django/db/models/sql | |
| parent | 1b05546bd50d1bf99e3d0e7def1238edf8d44065 (diff) | |
Fix proxy model Query.remove_inherited_models()
Fixed #18248 -- proxy models were added to included_inherited_models
in sql.query.Query. The variable is meant to be used for multitable
inheritance only. This mistake caused problems in situations where
proxy model's query was reused.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 13 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 15 |
2 files changed, 10 insertions, 18 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 69b508fe97..33949f5a71 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -261,12 +261,12 @@ 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() only_load = self.deferred_to_columns() - # Skip all proxy to the root proxied model - proxied_model = opts.concrete_model if start_alias: seen = {None: start_alias} @@ -277,12 +277,9 @@ class SQLCompiler(object): try: alias = seen[model] except KeyError: - if model is proxied_model: - alias = start_alias - else: - link_field = opts.get_ancestor_link(model) - alias = self.query.join((start_alias, model._meta.db_table, - link_field.column, model._meta.pk.column)) + link_field = opts.get_ancestor_link(model) + alias = self.query.join((start_alias, model._meta.db_table, + link_field.column, model._meta.pk.column)) seen[model] = alias else: # If we're starting from the base model of the queryset, the diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index efbc0c95a3..c91215fa9e 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -933,21 +933,16 @@ class Query(object): whereas column determination is a later part, and side-effect, of as_sql()). """ - opts = self.model._meta + # Skip all proxy models + opts = self.model._meta.concrete_model._meta root_alias = self.tables[0] seen = {None: root_alias} - # Skip all proxy to the root proxied model - proxied_model = opts.concrete_model - for field, model in opts.get_fields_with_model(): if model not in seen: - if model is proxied_model: - seen[model] = root_alias - else: - link_field = opts.get_ancestor_link(model) - seen[model] = self.join((root_alias, model._meta.db_table, - link_field.column, model._meta.pk.column)) + link_field = opts.get_ancestor_link(model) + seen[model] = self.join((root_alias, model._meta.db_table, + link_field.column, model._meta.pk.column)) self.included_inherited_models = seen def remove_inherited_models(self): |
