summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/expression.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-09-18 13:18:44 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-09-18 13:18:44 -0400
commit003149c504149849c679a60a1f346a0f0393dce0 (patch)
tree277f62e174b557001792168e60e8a7b288b67959 /lib/sqlalchemy/sql/expression.py
parentc9d7e387803a7cf7d3bcd22b0ba10bdbe2718e92 (diff)
downloadsqlalchemy-003149c504149849c679a60a1f346a0f0393dce0.tar.gz
- An informative error message is raised if a Column
which has not yet been assigned a name, i.e. as in declarative, is used in a context where it is exported to the columns collection of an enclosing select() construct, or if any construct involving that column is compiled before its name is assigned. [ticket:1862]
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r--lib/sqlalchemy/sql/expression.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 1b1cfee8a..70d5f13fc 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -1852,17 +1852,19 @@ class ColumnElement(ClauseElement, _CompareMixin):
descending selectable.
"""
-
- if name:
- co = ColumnClause(name, selectable, type_=getattr(self,
- 'type', None))
+ if name is None:
+ name = self.anon_label
+ # TODO: may want to change this to anon_label,
+ # or some value that is more useful than the
+ # compiled form of the expression
+ key = str(self)
else:
- name = str(self)
- co = ColumnClause(self.anon_label, selectable,
- type_=getattr(self, 'type', None))
-
+ key = name
+
+ co = ColumnClause(name, selectable, type_=getattr(self,
+ 'type', None))
co.proxies = [self]
- selectable.columns[name] = co
+ selectable.columns[key] = co
return co
def compare(self, other, use_proxies=False, equivalents=None, **kw):