zzzeek / test_sqlalchemy

0 stars 0 forks source link

using bound params on queries with union fails #986

Closed sqlalchemy-bot closed 16 years ago

sqlalchemy-bot commented 16 years ago

Issue created by Anonymous


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>
sqlalchemy-bot commented 10 years ago

Michael Bayer (zzzeek) wrote:


Removing milestone: 0.4.6 (automated comment)

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


sorry, typo, 8e0ea84c333aac2b28326084a03c48aa4a212f45

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


2b6e2defe593b4df2810df91193a8729ccea8e1c

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


sqlalchemy-bot commented 16 years ago

Anonymous wrote:


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.

sqlalchemy-bot commented 10 years ago

Changes by Michael Bayer (zzzeek): removed "0.4.6" milestone

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): set state to "resolved"

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): set state to "resolved"

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): changed priority from "major" to "critical"; changed component from "(none)" to "sql"; set milestone to "0.4.4"

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: removed "resolved" state