On 08/18/2010 10:27 AM, Alvaro Reinoso wrote:
> Hello,
>
> I'd like to query the database and get read-only objects with session
> object. I need to save the objects in my server and use them through
> the user session. If I use a object outside of the function that calls
> the database, I get this error:
>
> "DetachedInstanceError: Parent instance is not bound to a Session;
> lazy load operation of attribute 'items' cannot proceed"
>
> I don't need to make any change in those objects, so I don't need to
> load them again.
>
> Is there any way that I can get that?
>
> Thanks in advance!
>   

You have two options:

   1. Keep the DB session open longer so the objects can lazy-load
      attributes from the database.
   2. Ensure that all the attributes you will use are fully loaded in
      your "function that calls the database". Generally this means
      adding joinedload() or subqueryload() options to your DB queries.
      This will prevent lazy-loads from occurring and makes it safe to
      use the objects without a DB session.

-Conor

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to