Commits

Mike Bayer committed f8ca3c8

- approach the issue of "columns clause label" in a
type-based way to save on calls in columns_plus_names

Comments (0)

Files changed (2)

lib/sqlalchemy/sql/elements.py

     __visit_name__ = 'column'
     primary_key = False
     foreign_keys = []
-    _label = None
+    _label = _columns_clause_label = None
     _key_label = key = None
     _alt_names = ()
 
 
     _hide_froms = []
 
-    # help in those cases where text() is where a
-    # column expression usually is
-    key = _label = None
+    # help in those cases where text() is
+    # interpreted in a column expression situation
+    key = _label = _columns_clause_label = None
 
     def __init__(
             self,
             self.name = _anonymous_label(
                 '%%(%d %s)s' % (id(self), getattr(element, 'name', 'anon'))
             )
-        self.key = self._label = self._key_label = self.name
+        self.key = self._label = self._key_label = \
+            self._columns_clause_label = self.name
         self._element = element
         self._type = type_
         self._proxies = [element]
     def _label(self):
         return self._gen_label(self.name)
 
+    @_memoized_property
+    def _columns_clause_label(self):
+        if self.table is None:
+            return None
+        else:
+            return self._label
+
     def _gen_label(self, name):
         t = self.table
 

lib/sqlalchemy/sql/selectable.py

             names = set()
 
             def name_for_col(c):
-                if c._label is None or getattr(c, 'table', False) is None:
+                if c._columns_clause_label is None:
                     return (None, c)
-                name = c._label
+                name = c._columns_clause_label
                 if name in names:
                     name = c.anon_label
                 else: