diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-26 15:45:52 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-26 15:45:52 -0500 |
commit | 6aeec027a0fb33348bdb8ec5b448044a67eff7c5 (patch) | |
tree | f7f1528f6827e1259678904765db296fdd016324 /lib/sqlalchemy/sql/elements.py | |
parent | 302ad6228a12fe5cb4c5d332e5bab65ed373bc01 (diff) | |
download | sqlalchemy-6aeec027a0fb33348bdb8ec5b448044a67eff7c5.tar.gz |
- 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
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 15 |
1 files changed, 9 insertions, 6 deletions
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". |