Hello List,
the problem I am facing is that _deep_deannotate, which is used in
ColumnProperty.__init__, breaks the FROM clause of my select() object if
this select() has a JOIN (either left or right, doesn't matter) as from_obj
in it, _where the initial table is aliased_.
To illustrate I'll append my testcase. I traced it down
to Select._copy_internals(), line 4907 in sqlalchemy.sql.expression, where
the call to s._from_obj.union(s._froms) will happily add an the initial
table _a second time_ to the FROM clause, (it is already part of the join
object) resulting in an error from the database because the alias is
duplicated in the generated SQL.
Taking any hints on how to fix this. :)
Reproduced in 0.7.6
thanks,
Christoph
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/w1P2N5cbeL4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.
#!/usr/bin/env python
# encoding: utf-8
# This is an illustration of a problem with column_properties where
# the from_obj contains joined aliased tables.
from sqlalchemy import Table, Column, Integer, ForeignKey, MetaData
from sqlalchemy import select
from sqlalchemy.sql.util import _deep_deannotate
metadata = MetaData()
orders = Table(
'orders', metadata,
Column('order_id', Integer, primary_key=True),
)
item = Table(
'item', metadata,
Column('item_id', Integer, primary_key=True),
Column('order_id', Integer, ForeignKey('orders.order_id')),
)
a = item
b = a.outerjoin(orders)
s = select([a.c.item_id], from_obj=b)
# OK. This is how the select should look like.
print s
print _deep_deannotate(s)
print
a = item.alias()
b = a.outerjoin(orders)
s = select([a.c.item_id], from_obj=b)
print s
# XXX Not OK. Look at the FROM clause of this select
print _deep_deannotate(s)