Re: [Sqlalchemy-tickets] [sqlalchemy] #2932: textasfrom compatibility with columns, query
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2014-02-07 18:25:59
|
#2932: textasfrom compatibility with columns, query
------------------------------+-------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: defect | Status: reopened
Priority: highest | Milestone: 0.9.3
Component: sql | Severity: major - 1-3 hours
Resolution: | Keywords:
Progress State: in progress |
------------------------------+-------------------------------
Changes (by zzzeek):
* status: closed => reopened
* resolution: fixed =>
* status_field: completed/closed => in progress
Comment:
OK how about this:
{{{
#!python
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import column
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
data = Column(String)
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
sess = Session(e)
sess.add_all([A(data='a1'), A(data='a2')])
sess.commit()
result = sess.query(A).from_statement(
text("SELECT id AS x, data AS y FROM a").
columns(A.id.label("x"), A.data.label("y"))
).all()
}}}
to make that work we need to do this:
{{{
#!diff
diff --git a/lib/sqlalchemy/sql/compiler.py
b/lib/sqlalchemy/sql/compiler.py
index d4b0807..ad81503 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -618,7 +618,7 @@ class SQLCompiler(Compiled):
if populate_result_map:
for c in taf.c:
self._add_to_result_map(
- c.key, c.key, (c,), c.type
+ c.key, c.key, tuple(c.proxy_set), c.type
)
text = self.process(taf.element, **kw)
}}}
so, if the text() is made against a column on an aliased() - does
c.proxy_set cover too broad of an area? I think so so maybe instead we
really want this:
{{{
#!diff
diff --git a/lib/sqlalchemy/sql/compiler.py
b/lib/sqlalchemy/sql/compiler.py
index d4b0807..f2a8b3e 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -618,7 +618,7 @@ class SQLCompiler(Compiled):
if populate_result_map:
for c in taf.c:
self._add_to_result_map(
- c.key, c.key, (c,), c.type
+ c.key, c.key, (c, ) + tuple(c._proxies), c.type
)
text = self.process(taf.element, **kw)
}}}
we'd need to test a text() that is hitting "cls" plus "aliased(cls)".
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2932#comment:5>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|