using bound params on queries with union fails
Issue #986
resolved
When using bound parameters within a query which involves the UNION of two selects, then substituting in values using the unique_params method fails.
Here is the code to reproduce the issue
from sqlalchemy import *
from sqlalchemy.sql import bindparam
table1 = Table('table1', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(255), unique=True)
)
table2 = Table('table2', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(255), unique=True)
)
s1 = select([table1](table1), table1.c.id == bindparam('id_param'))
s2 = select([table2](table2))
u = union(s1, s2)
# this next line works fine
s1.unique_params(id_param = 9)
# but this one doesn't
u.unique_params(id_param = 4)
and here's the trace of the error you get
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
expression.py", line 911, in unique_params
return self._params(True, optionaldict, kwargs)
File "C:\Python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
expression.py", line 939, in _params
return visitors.traverse(self, visit_bindparam=visit_bindparam, clone=True)
File "c:\python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
visitors.py", line 108, in traverse
return Vis().traverse(clause, clone=clone)
File "c:\python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
visitors.py", line 69, in traverse
for c in t.get_children(**self.__traverse_options__):
File "C:\Python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
expression.py", line 2975, in get_children
[self._group_by_clause](self._order_by_clause,) + list(self.selects)
File "C:\Python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
expression.py", line 1676, in attr
self._export_columns()
File "C:\Python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
expression.py", line 1696, in _export_columns
cp = self._proxy_column(co)
File "C:\Python25\lib\site-packages\sqlalchemy-0.4.3-py2.5.egg\sqlalchemy\sql\
expression.py", line 2961, in _proxy_column
existing = self._col_map[self.selects[0](self.selects[0)][- 1](len(col_ordering))
KeyError: <sqlalchemy.sql.expression.Select at 0x1ed8610; Select object>
Comments (5)
-
repo owner -
repo owner - changed status to resolved
-
Account Deleted - changed status to open
- removed status
Changeset 2b6e2defe593b4df2810df91193a8729ccea8e1c doesn't seem to have any bearing on the bug being reported. Perhaps it's the wrong link? I have applied the changes 4125 and the issue persists.
-
repo owner - changed status to resolved
sorry, typo, 8e0ea84c333aac2b28326084a03c48aa4a212f45
-
repo owner - removed milestone
Removing milestone: 0.4.6 (automated comment)
- Log in to comment