On Tuesday, April 25, 2017 at 5:50:48 AM UTC-4, Simon King wrote:
 

>
> def reload(instance, *options): 
>     session = saorm.object_session(instance) 
>     # TODO: make this generic rather than assuming presence of 'id' column 
>     q = (session.query(type(instance)) 
>          .filter_by(id=instance.id) 
>          .options(*options)) 
>     return q.one() 
>
> (I don't really understand the concern about grabbing the session from 
> the object) 
>


Thanks, Simon.  That's a smart approach.

I wasn't thinking in terms of re-use, and had a one-off need -- and must 
avoid that `reload` functionality as a one-off part of the code.  A 
function like that works perfectly for my needs.

The concern around this is largely on maintainability.  We have a few 
categories of code that can't explicitly use SA, and this falls into one of 
them.  So the issue isn't as much of 'grabbing the session from the object' 
in general, but doing so in that block of code.  

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to