.. changelog::
:version: 0.9.4
+ .. change::
+ :tags: bug, sql
+ :tickets: 2974
+
+ 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.
+
.. change::
:tags: bug, sql
:tickets: 2974
primary_key = False
foreign_keys = []
_label = None
- _key_label = None
+ _key_label = key = None
_alt_names = ()
def self_group(self, against=None):
"""
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(
'name', 'anon')))
-
class BindParameter(ColumnElement):
"""Represent a "bound expression".
)
def test_naming(self):
+ # TODO: the part where we check c.keys() are not "compile" tests, they
+ # belong probably in test_selectable, or some broken up
+ # version of that suite
+
f1 = func.hoho(table1.c.name)
s1 = select([table1.c.myid, table1.c.myid.label('foobar'),
f1,
exprs = (
table1.c.myid == 12,
func.hoho(table1.c.myid),
- cast(table1.c.name, Numeric)
+ cast(table1.c.name, Numeric),
+ literal('x'),
)
for col, key, expr, label in (
(table1.c.name, 'name', 'mytable.name', None),
'CAST(mytable.name AS NUMERIC)', 'anon_1'),
(t1.c.col1, 'col1', 'mytable.col1', None),
(column('some wacky thing'), 'some wacky thing',
- '"some wacky thing"', '')
+ '"some wacky thing"', ''),
+ (exprs[3], exprs[3].key, ":param_1", "anon_1")
):
if getattr(col, 'table', None) is not None:
t = col.table
"""
table1 = self.tables.mytable
expr = func.foo(table1.c.myid)
- assert not hasattr(expr, 'key')
+ eq_(expr.key, None)
self.assert_compile(table1.update().values({expr: 'bar'}),
'UPDATE mytable SET foo(myid)=:param_1')