Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20413 - Respect Query.get_meta()

  • Loading branch information...
commit 74f3884ae04ea57baee9b04ab0b5658a97cfd296 1 parent ebfb71c
Mike Fogel authored
4  django/contrib/gis/db/models/sql/compiler.py
@@ -121,7 +121,7 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
121 121
         """
122 122
         result = []
123 123
         if opts is None:
124  
-            opts = self.query.model._meta
  124
+            opts = self.get_meta()
125 125
         aliases = set()
126 126
         only_load = self.deferred_to_columns()
127 127
         seen = self.query.included_inherited_models.copy()
@@ -247,7 +247,7 @@ def _field_column(self, field, table_alias=None, column=None):
247 247
         used.  If `column` is specified, it will be used instead of the value
248 248
         in `field.column`.
249 249
         """
250  
-        if table_alias is None: table_alias = self.query.model._meta.db_table
  250
+        if table_alias is None: table_alias = self.get_meta().db_table
251 251
         return "%s.%s" % (self.quote_name_unless_alias(table_alias),
252 252
                           self.connection.ops.quote_name(column or field.column))
253 253
 
2  django/db/models/query.py
@@ -869,7 +869,7 @@ def ordered(self):
869 869
         """
870 870
         if self.query.extra_order_by or self.query.order_by:
871 871
             return True
872  
-        elif self.query.default_ordering and self.query.model._meta.ordering:
  872
+        elif self.query.default_ordering and self.query.get_meta().ordering:
873 873
             return True
874 874
         else:
875 875
             return False
24  django/db/models/sql/compiler.py
@@ -32,7 +32,7 @@ def pre_sql_setup(self):
32 32
         # cleaned. We are not using a clone() of the query here.
33 33
         """
34 34
         if not self.query.tables:
35  
-            self.query.join((None, self.query.model._meta.db_table, None))
  35
+            self.query.join((None, self.query.get_meta().db_table, None))
36 36
         if (not self.query.select and self.query.default_cols and not
37 37
                 self.query.included_inherited_models):
38 38
             self.query.setup_inherited_models()
@@ -260,7 +260,7 @@ def get_default_columns(self, with_aliases=False, col_aliases=None,
260 260
         """
261 261
         result = []
262 262
         if opts is None:
263  
-            opts = self.query.model._meta
  263
+            opts = self.query.get_meta()
264 264
         qn = self.quote_name_unless_alias
265 265
         qn2 = self.connection.ops.quote_name
266 266
         aliases = set()
@@ -309,7 +309,7 @@ def get_distinct(self):
309 309
         qn = self.quote_name_unless_alias
310 310
         qn2 = self.connection.ops.quote_name
311 311
         result = []
312  
-        opts = self.query.model._meta
  312
+        opts = self.query.get_meta()
313 313
 
314 314
         for name in self.query.distinct_fields:
315 315
             parts = name.split(LOOKUP_SEP)
@@ -338,7 +338,7 @@ def get_ordering(self):
338 338
             ordering = self.query.order_by
339 339
         else:
340 340
             ordering = (self.query.order_by
341  
-                        or self.query.model._meta.ordering
  341
+                        or self.query.get_meta().ordering
342 342
                         or [])
343 343
         qn = self.quote_name_unless_alias
344 344
         qn2 = self.connection.ops.quote_name
@@ -388,7 +388,7 @@ def get_ordering(self):
388 388
                 # 'col' is of the form 'field' or 'field1__field2' or
389 389
                 # '-field1__field2__field', etc.
390 390
                 for table, cols, order in self.find_ordering_name(field,
391  
-                        self.query.model._meta, default_order=asc):
  391
+                        self.query.get_meta(), default_order=asc):
392 392
                     for col in cols:
393 393
                         if (table, col) not in processed_pairs:
394 394
                             elt = '%s.%s' % (qn(table), qn2(col))
@@ -556,10 +556,10 @@ def get_grouping(self, having_group_by, ordering_group_by):
556 556
             select_cols = self.query.select + self.query.related_select_cols
557 557
             # Just the column, not the fields.
558 558
             select_cols = [s[0] for s in select_cols]
559  
-            if (len(self.query.model._meta.concrete_fields) == len(self.query.select)
  559
+            if (len(self.query.get_meta().concrete_fields) == len(self.query.select)
560 560
                     and self.connection.features.allows_group_by_pk):
561 561
                 self.query.group_by = [
562  
-                    (self.query.model._meta.db_table, self.query.model._meta.pk.column)
  562
+                    (self.query.get_meta().db_table, self.query.get_meta().pk.column)
563 563
                 ]
564 564
                 select_cols = []
565 565
             seen = set()
@@ -716,14 +716,14 @@ def results_iter(self):
716 716
                         if self.query.select:
717 717
                             fields = [f.field for f in self.query.select]
718 718
                         else:
719  
-                            fields = self.query.model._meta.concrete_fields
  719
+                            fields = self.query.get_meta().concrete_fields
720 720
                         fields = fields + [f.field for f in self.query.related_select_cols]
721 721
 
722 722
                         # If the field was deferred, exclude it from being passed
723 723
                         # into `resolve_columns` because it wasn't selected.
724 724
                         only_load = self.deferred_to_columns()
725 725
                         if only_load:
726  
-                            db_table = self.query.model._meta.db_table
  726
+                            db_table = self.query.get_meta().db_table
727 727
                             fields = [f for f in fields if db_table in only_load and
728 728
                                       f.column in only_load[db_table]]
729 729
                     row = self.resolve_columns(row, fields)
@@ -825,7 +825,7 @@ def as_sql(self):
825 825
         # We don't need quote_name_unless_alias() here, since these are all
826 826
         # going to be column names (so we can avoid the extra overhead).
827 827
         qn = self.connection.ops.quote_name
828  
-        opts = self.query.model._meta
  828
+        opts = self.query.get_meta()
829 829
         result = ['INSERT INTO %s' % qn(opts.db_table)]
830 830
 
831 831
         has_fields = bool(self.query.fields)
@@ -887,7 +887,7 @@ def execute_sql(self, return_id=False):
887 887
         if self.connection.features.can_return_id_from_insert:
888 888
             return self.connection.ops.fetch_returned_insert_id(cursor)
889 889
         return self.connection.ops.last_insert_id(cursor,
890  
-                self.query.model._meta.db_table, self.query.model._meta.pk.column)
  890
+                self.query.get_meta().db_table, self.query.get_meta().pk.column)
891 891
 
892 892
 
893 893
 class SQLDeleteCompiler(SQLCompiler):
@@ -992,7 +992,7 @@ def pre_sql_setup(self):
992 992
         query.bump_prefix()
993 993
         query.extra = {}
994 994
         query.select = []
995  
-        query.add_fields([query.model._meta.pk.name])
  995
+        query.add_fields([query.get_meta().pk.name])
996 996
         # Recheck the count - it is possible that fiddling with the select
997 997
         # fields above removes tables from the query. Refs #18304.
998 998
         count = query.count_active_tables()
10  django/db/models/sql/query.py
@@ -552,7 +552,7 @@ def deferred_to_data(self, target, callback):
552 552
         field_names, defer = self.deferred_loading
553 553
         if not field_names:
554 554
             return
555  
-        orig_opts = self.model._meta
  555
+        orig_opts = self.get_meta()
556 556
         seen = {}
557 557
         must_include = {orig_opts.concrete_model: set([orig_opts.pk])}
558 558
         for field_name in field_names:
@@ -818,7 +818,7 @@ def get_initial_alias(self):
818 818
             alias = self.tables[0]
819 819
             self.ref_alias(alias)
820 820
         else:
821  
-            alias = self.join((None, self.model._meta.db_table, None))
  821
+            alias = self.join((None, self.get_meta().db_table, None))
822 822
         return alias
823 823
 
824 824
     def count_active_tables(self):
@@ -906,7 +906,7 @@ def setup_inherited_models(self):
906 906
         whereas column determination is a later part, and side-effect, of
907 907
         as_sql()).
908 908
         """
909  
-        opts = self.model._meta
  909
+        opts = self.get_meta()
910 910
         root_alias = self.tables[0]
911 911
         seen = {None: root_alias}
912 912
 
@@ -1624,7 +1624,7 @@ def add_count_column(self):
1624 1624
                         "Cannot add count col with multiple cols in 'select': %r" % self.select
1625 1625
                 count = self.aggregates_module.Count(self.select[0].col)
1626 1626
         else:
1627  
-            opts = self.model._meta
  1627
+            opts = self.get_meta()
1628 1628
             if not self.select:
1629 1629
                 count = self.aggregates_module.Count(
1630 1630
                     (self.join((None, opts.db_table, None)), opts.pk.column),
@@ -1732,7 +1732,7 @@ def add_immediate_loading(self, field_names):
1732 1732
         field_names = set(field_names)
1733 1733
         if 'pk' in field_names:
1734 1734
             field_names.remove('pk')
1735  
-            field_names.add(self.model._meta.pk.name)
  1735
+            field_names.add(self.get_meta().pk.name)
1736 1736
 
1737 1737
         if defer:
1738 1738
             # Remove any existing deferred names from the current set before
10  django/db/models/sql/subqueries.py
@@ -41,12 +41,12 @@ def delete_batch(self, pk_list, using, field=None):
41 41
         lot of values in pk_list.
42 42
         """
43 43
         if not field:
44  
-            field = self.model._meta.pk
  44
+            field = self.get_meta().pk
45 45
         for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
46 46
             where = self.where_class()
47 47
             where.add((Constraint(None, field.column, field), 'in',
48 48
                        pk_list[offset:offset + GET_ITERATOR_CHUNK_SIZE]), AND)
49  
-            self.do_query(self.model._meta.db_table, where, using=using)
  49
+            self.do_query(self.get_meta().db_table, where, using=using)
50 50
 
51 51
     def delete_qs(self, query, using):
52 52
         """
@@ -112,7 +112,7 @@ def clone(self, klass=None, **kwargs):
112 112
                 related_updates=self.related_updates.copy(), **kwargs)
113 113
 
114 114
     def update_batch(self, pk_list, values, using):
115  
-        pk_field = self.model._meta.pk
  115
+        pk_field = self.get_meta().pk
116 116
         self.add_update_values(values)
117 117
         for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
118 118
             self.where = self.where_class()
@@ -129,7 +129,7 @@ def add_update_values(self, values):
129 129
         """
130 130
         values_seq = []
131 131
         for name, val in six.iteritems(values):
132  
-            field, model, direct, m2m = self.model._meta.get_field_by_name(name)
  132
+            field, model, direct, m2m = self.get_meta().get_field_by_name(name)
133 133
             if not direct or m2m:
134 134
                 raise FieldError('Cannot update model field %r (only non-relations and foreign keys permitted).' % field)
135 135
             if model:
@@ -236,7 +236,7 @@ def add_select(self, field_name, lookup_type, order='ASC'):
236 236
             )
237 237
         except FieldError:
238 238
             raise FieldDoesNotExist("%s has no field named '%s'" % (
239  
-                self.model._meta.object_name, field_name
  239
+                self.get_meta().object_name, field_name
240 240
             ))
241 241
         field = result[0]
242 242
         self._check_field(field)                # overridden in DateTimeQuery

0 notes on commit 74f3884

Please sign in to comment.
Something went wrong with that request. Please try again.