I have changed my code to be like this:
job = session.merge(job)
# Merge docs says that object does not get into the session
session.add(job)
log.info("Job finished! %s" % job.file)
When using latest SQLAlchemy trunk and 0.5.6 sometimes i get
UnboundExecutionError.
Also, i can assure that all my attributes are loaded - i use all of them before
and no error occurs.
Maybe there's something wrong with the way i'm getting the session:
session = Session.object_session(job)
if not session:
session = Session()
On Nov 16, 2009, at 3:27 PM, Michael Bayer wrote:
>
> Fernando Takai wrote:
>>
>> Hi all!
>>
>> I've experiencing this problem for some time now and even after
>> debugging, i could not find why it happens.
>>
>> I have a medium sized multi-thread application that manipulates
>> SQLAlchemy objects - the objects are passed from thread to thread, so,
>> when i load an instance i close the session.
>>
>> After working on the object, i need to update the status of the it, so
>> i do something like this:
>>
>> job.status = FINISHED
>> session.add(job)
>> log.info("Finished job %s" % job.filename)
>> session.flush()
>>
>> This code works pretty well, but from time to time, i get this on the
>> logs:
>>
>> "UnboundExecutionError: Instance <Job at 0x413ee50> is not bound to a
>> Session; attribute refresh operation cannot proceed"
>>
>> The complete stacktrace is here: http://pastebin.org/54196
>>
>> Could this be happening because of my pool_recycle setting (300
>> seconds) ?
>
> its not related to the pool. Your objects have expired or unloaded
> attributes present on them which will attempt to load when accessed. The
> object must be attached to a Session for this to proceed.
>
> the easiest way to deal with this is to merge() the objects into a new
> thread-local Session before using.
>
> Alternatively, ensure all required attributes are loaded. This often
> requires touching the attributes explicitly in the case of joined table
> inheritance or lazily-loaded relations(). Also note that calling
> session.commit() or session.rollback() expires all attributes, so avoid
> these in the case of objects becoming detached, or expunge() the objects
> before an expiration occurs.
>
>
>
> >
--
Fernando Takai
http://twitter.com/fernando_takai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---