Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoided storing ExpressionNodes in dicts

  • Loading branch information...
commit ddd7d1af203d6d260c970d8ee8749fedbce6bba1 1 parent ab2a177
@akaariai akaariai authored
Showing with 16 additions and 6 deletions.
  1. +16 −6 django/db/models/sql/expressions.py
View
22 django/db/models/sql/expressions.py
@@ -6,7 +6,7 @@ class SQLEvaluator(object):
def __init__(self, expression, query, allow_joins=True):
self.expression = expression
self.opts = query.get_meta()
- self.cols = {}
+ self.cols = []
self.contains_aggregate = False
self.expression.prepare(self, query, allow_joins)
@@ -18,11 +18,15 @@ def as_sql(self, qn, connection):
return self.expression.evaluate(self, qn, connection)
def relabel_aliases(self, change_map):
- for node, col in self.cols.items():
+ new_cols = []
+ for node, col in self.cols:
if hasattr(col, "relabel_aliases"):
col.relabel_aliases(change_map)
+ new_cols.append((node, col))
else:
- self.cols[node] = (change_map.get(col[0], col[0]), col[1])
+ new_cols.append((node,
+ (change_map.get(col[0], col[0]), col[1])))
+ self.cols = new_cols
#####################################################
# Vistor methods for initial expression preparation #
@@ -41,7 +45,7 @@ def prepare_leaf(self, node, query, allow_joins):
if (len(field_list) == 1 and
node.name in query.aggregate_select.keys()):
self.contains_aggregate = True
- self.cols[node] = query.aggregate_select[node.name]
+ self.cols.append((node, query.aggregate_select[node.name]))
else:
try:
field, source, opts, join_list, last, _ = query.setup_joins(
@@ -49,7 +53,7 @@ def prepare_leaf(self, node, query, allow_joins):
query.get_initial_alias(), False)
col, _, join_list = query.trim_joins(source, join_list, last, False)
- self.cols[node] = (join_list[-1], col)
+ self.cols.append((node, (join_list[-1], col)))
except FieldDoesNotExist:
raise FieldError("Cannot resolve keyword %r into field. "
"Choices are: %s" % (self.name,
@@ -80,7 +84,13 @@ def evaluate_node(self, node, qn, connection):
return connection.ops.combine_expression(node.connector, expressions), expression_params
def evaluate_leaf(self, node, qn, connection):
- col = self.cols[node]
+ col = None
+ for n, c in self.cols:
+ if n is node:
+ col = c
+ break
+ if col is None:
+ raise ValueError("Given node not found")
if hasattr(col, 'as_sql'):
return col.as_sql(qn, connection), ()
else:
Please sign in to comment.
Something went wrong with that request. Please try again.