Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20413 - Respect Query.get_meta()

  • Loading branch information...
commit 74f3884ae04ea57baee9b04ab0b5658a97cfd296 1 parent ebfb71c
Mike Fogel mfogel authored
4 django/contrib/gis/db/models/sql/compiler.py
View
@@ -121,7 +121,7 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
"""
result = []
if opts is None:
- opts = self.query.model._meta
+ opts = self.get_meta()
aliases = set()
only_load = self.deferred_to_columns()
seen = self.query.included_inherited_models.copy()
@@ -247,7 +247,7 @@ def _field_column(self, field, table_alias=None, column=None):
used. If `column` is specified, it will be used instead of the value
in `field.column`.
"""
- if table_alias is None: table_alias = self.query.model._meta.db_table
+ if table_alias is None: table_alias = self.get_meta().db_table
return "%s.%s" % (self.quote_name_unless_alias(table_alias),
self.connection.ops.quote_name(column or field.column))
2  django/db/models/query.py
View
@@ -869,7 +869,7 @@ def ordered(self):
"""
if self.query.extra_order_by or self.query.order_by:
return True
- elif self.query.default_ordering and self.query.model._meta.ordering:
+ elif self.query.default_ordering and self.query.get_meta().ordering:
return True
else:
return False
24 django/db/models/sql/compiler.py
View
@@ -32,7 +32,7 @@ def pre_sql_setup(self):
# cleaned. We are not using a clone() of the query here.
"""
if not self.query.tables:
- self.query.join((None, self.query.model._meta.db_table, None))
+ self.query.join((None, self.query.get_meta().db_table, None))
if (not self.query.select and self.query.default_cols and not
self.query.included_inherited_models):
self.query.setup_inherited_models()
@@ -260,7 +260,7 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
"""
result = []
if opts is None:
- opts = self.query.model._meta
+ opts = self.query.get_meta()
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
aliases = set()
@@ -309,7 +309,7 @@ def get_distinct(self):
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
result = []
- opts = self.query.model._meta
+ opts = self.query.get_meta()
for name in self.query.distinct_fields:
parts = name.split(LOOKUP_SEP)
@@ -338,7 +338,7 @@ def get_ordering(self):
ordering = self.query.order_by
else:
ordering = (self.query.order_by
- or self.query.model._meta.ordering
+ or self.query.get_meta().ordering
or [])
qn = self.quote_name_unless_alias
qn2 = self.connection.ops.quote_name
@@ -388,7 +388,7 @@ def get_ordering(self):
# 'col' is of the form 'field' or 'field1__field2' or
# '-field1__field2__field', etc.
for table, cols, order in self.find_ordering_name(field,
- self.query.model._meta, default_order=asc):
+ self.query.get_meta(), default_order=asc):
for col in cols:
if (table, col) not in processed_pairs:
elt = '%s.%s' % (qn(table), qn2(col))
@@ -556,10 +556,10 @@ def get_grouping(self, having_group_by, ordering_group_by):
select_cols = self.query.select + self.query.related_select_cols
# Just the column, not the fields.
select_cols = [s[0] for s in select_cols]
- if (len(self.query.model._meta.concrete_fields) == len(self.query.select)
+ if (len(self.query.get_meta().concrete_fields) == len(self.query.select)
and self.connection.features.allows_group_by_pk):
self.query.group_by = [
- (self.query.model._meta.db_table, self.query.model._meta.pk.column)
+ (self.query.get_meta().db_table, self.query.get_meta().pk.column)
]
select_cols = []
seen = set()
@@ -716,14 +716,14 @@ def results_iter(self):
if self.query.select:
fields = [f.field for f in self.query.select]
else:
- fields = self.query.model._meta.concrete_fields
+ fields = self.query.get_meta().concrete_fields
fields = fields + [f.field for f in self.query.related_select_cols]
# If the field was deferred, exclude it from being passed
# into `resolve_columns` because it wasn't selected.
only_load = self.deferred_to_columns()
if only_load:
- db_table = self.query.model._meta.db_table
+ db_table = self.query.get_meta().db_table
fields = [f for f in fields if db_table in only_load and
f.column in only_load[db_table]]
row = self.resolve_columns(row, fields)
@@ -825,7 +825,7 @@ def as_sql(self):
# We don't need quote_name_unless_alias() here, since these are all
# going to be column names (so we can avoid the extra overhead).
qn = self.connection.ops.quote_name
- opts = self.query.model._meta
+ opts = self.query.get_meta()
result = ['INSERT INTO %s' % qn(opts.db_table)]
has_fields = bool(self.query.fields)
@@ -887,7 +887,7 @@ def execute_sql(self, return_id=False):
if self.connection.features.can_return_id_from_insert:
return self.connection.ops.fetch_returned_insert_id(cursor)
return self.connection.ops.last_insert_id(cursor,
- self.query.model._meta.db_table, self.query.model._meta.pk.column)
+ self.query.get_meta().db_table, self.query.get_meta().pk.column)
class SQLDeleteCompiler(SQLCompiler):
@@ -992,7 +992,7 @@ def pre_sql_setup(self):
query.bump_prefix()
query.extra = {}
query.select = []
- query.add_fields([query.model._meta.pk.name])
+ query.add_fields([query.get_meta().pk.name])
# Recheck the count - it is possible that fiddling with the select
# fields above removes tables from the query. Refs #18304.
count = query.count_active_tables()
10 django/db/models/sql/query.py
View
@@ -552,7 +552,7 @@ def deferred_to_data(self, target, callback):
field_names, defer = self.deferred_loading
if not field_names:
return
- orig_opts = self.model._meta
+ orig_opts = self.get_meta()
seen = {}
must_include = {orig_opts.concrete_model: set([orig_opts.pk])}
for field_name in field_names:
@@ -818,7 +818,7 @@ def get_initial_alias(self):
alias = self.tables[0]
self.ref_alias(alias)
else:
- alias = self.join((None, self.model._meta.db_table, None))
+ alias = self.join((None, self.get_meta().db_table, None))
return alias
def count_active_tables(self):
@@ -906,7 +906,7 @@ def setup_inherited_models(self):
whereas column determination is a later part, and side-effect, of
as_sql()).
"""
- opts = self.model._meta
+ opts = self.get_meta()
root_alias = self.tables[0]
seen = {None: root_alias}
@@ -1624,7 +1624,7 @@ def add_count_column(self):
"Cannot add count col with multiple cols in 'select': %r" % self.select
count = self.aggregates_module.Count(self.select[0].col)
else:
- opts = self.model._meta
+ opts = self.get_meta()
if not self.select:
count = self.aggregates_module.Count(
(self.join((None, opts.db_table, None)), opts.pk.column),
@@ -1732,7 +1732,7 @@ def add_immediate_loading(self, field_names):
field_names = set(field_names)
if 'pk' in field_names:
field_names.remove('pk')
- field_names.add(self.model._meta.pk.name)
+ field_names.add(self.get_meta().pk.name)
if defer:
# Remove any existing deferred names from the current set before
10 django/db/models/sql/subqueries.py
View
@@ -41,12 +41,12 @@ def delete_batch(self, pk_list, using, field=None):
lot of values in pk_list.
"""
if not field:
- field = self.model._meta.pk
+ field = self.get_meta().pk
for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
where = self.where_class()
where.add((Constraint(None, field.column, field), 'in',
pk_list[offset:offset + GET_ITERATOR_CHUNK_SIZE]), AND)
- self.do_query(self.model._meta.db_table, where, using=using)
+ self.do_query(self.get_meta().db_table, where, using=using)
def delete_qs(self, query, using):
"""
@@ -112,7 +112,7 @@ def clone(self, klass=None, **kwargs):
related_updates=self.related_updates.copy(), **kwargs)
def update_batch(self, pk_list, values, using):
- pk_field = self.model._meta.pk
+ pk_field = self.get_meta().pk
self.add_update_values(values)
for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
self.where = self.where_class()
@@ -129,7 +129,7 @@ def add_update_values(self, values):
"""
values_seq = []
for name, val in six.iteritems(values):
- field, model, direct, m2m = self.model._meta.get_field_by_name(name)
+ field, model, direct, m2m = self.get_meta().get_field_by_name(name)
if not direct or m2m:
raise FieldError('Cannot update model field %r (only non-relations and foreign keys permitted).' % field)
if model:
@@ -236,7 +236,7 @@ def add_select(self, field_name, lookup_type, order='ASC'):
)
except FieldError:
raise FieldDoesNotExist("%s has no field named '%s'" % (
- self.model._meta.object_name, field_name
+ self.get_meta().object_name, field_name
))
field = result[0]
self._check_field(field) # overridden in DateTimeQuery
Please sign in to comment.
Something went wrong with that request. Please try again.