From 6aeec027a0fb33348bdb8ec5b448044a67eff7c5 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 26 Feb 2014 15:45:52 -0500 Subject: - Adjusted the logic which applies names to the .c collection when a no-name :class:`.BindParameter` is received, e.g. via :func:`.sql.literal` or similar; the "key" of the bind param is used as the key within .c. rather than the rendered name. Since these binds have "anonymous" names in any case, this allows individual bound parameters to have their own name within a selectable if they are otherwise unlabeled. fixes #2974 --- lib/sqlalchemy/sql/elements.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 1b49a7cd1..f2ce0619c 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -588,7 +588,7 @@ class ColumnElement(ClauseElement, operators.ColumnOperators): primary_key = False foreign_keys = [] _label = None - _key_label = None + _key_label = key = None _alt_names = () def self_group(self, against=None): @@ -681,10 +681,14 @@ class ColumnElement(ClauseElement, operators.ColumnOperators): """ if name is None: name = self.anon_label - try: - key = str(self) - except exc.UnsupportedCompilationError: - key = self.anon_label + if self.key: + key = self.key + else: + try: + key = str(self) + except exc.UnsupportedCompilationError: + key = self.anon_label + else: key = name co = ColumnClause( @@ -755,7 +759,6 @@ class ColumnElement(ClauseElement, operators.ColumnOperators): 'name', 'anon'))) - class BindParameter(ColumnElement): """Represent a "bound expression". -- cgit v1.2.1