On Feb 2, 2014, at 12:08 AM, Matthew Phipps <[email protected]> wrote:
>
> db.session.commit()
> typemap = {'id': db.Integer, 'username': db.String, 'email': db.String,
> 'random_time': UTCDateTime}
> taf = text.columns(**typemap)
> users = db.session.query(User).from_statement(taf).all()
>
> This results in a stack trace:
>
>
> AttributeError: 'TextAsFrom' object has no attribute 'use_labels'
>
> Looks like TextAsFrom isn't quite select-like enough for from_statement(). I
> tried tacking on a taf.use_labels = True before running the query, but just
> got another error:
>
> NoSuchColumnError Traceback (most recent call last)
> <ipython-input-23-c694595d6ec1> in <module>()
> ----> 1 users = db.session.query(User).from_statement(taf).all()
>
>
> NoSuchColumnError: "Could not locate column in row for column 'user.id'"
>
> Any ideas? Incidentally, we can use the taf object in a session.execute() and
> get great results back, type processing and all. Problem is, they're just
> tuples (or a ResultProxy before you fetchall or iterate over it). Any way to
> convince SQLAlchemy to turn that result set into User objects, or at that
> point should we just send those to User() ourselves?
so this is good you worked through both issues that I’m fixing for
http://www.sqlalchemy.org/trac/ticket/2932. So besides the “use_labels” part,
the other thing that can make it work in 0.9.1 is to link the statement to the
mapped Column objects themselves:
from sqlalchemy.sql.selectable import TextAsFrom
TextAsFrom.use_labels = True
s.query(User).from_statement(
text("select * from users order by id").\
columns(User.id, User.name)
)
I’m committing 2932 in a moment and I’m super really hoping I can put out 0.9.2
today but it’s easy for me to run out of time, but 0.9.2 is definitely due.
signature.asc
Description: Message signed with OpenPGP using GPGMail
