Issues

Issue #3156 new

support MapperProperty population of text().columns() for use with query.from_statement()

Serge Koval
created an issue

I'm working on query precompilation layer and stumbled upon a bug: PickleType column does not automatically unpickle data received from the database.

[10]: m = db.session.query(Report).from_statement('SELECT * FROM reports LIMIT 1').all()

[11]: m[0].pickled_data
?}q(UurlqX634/654/aqgvppyv.jpgUserverqUcheetahUmodeqKUsizeqM?Du.

Just in case, using PostgreSQL.

Comments (4)

  1. Mike Bayer repo owner

    for now you need to specify these columns using the text() approach, that is:

    sess.query(Report).from_statement(text("select * from reports limit 1").columns(pickled_data=PickleType)).all()
    

    There is a potential feature add here which I will target at 1.0, but in all likelihood this would be a 1.1 thing as 1.0 is getting pretty full. The current mechanism with from_statement() is that the SQL result from this statement is formed independently of the Query() object and any of its metadata, so it is executed using Core without any knowledge that the results will be fed into a Report object.

    The feature would involve enhancing all implementations of MapperProperty.setup_context() to be able to add the appropriate Column objects to a given text() construct.

  2. Log in to comment