On Dec 27, 2011, at 4:54 AM, Arturo Sevilla wrote:

> Thanks for the code, your example runs without a problem.
> 
> I've managed to "locate" the error. In reality it doesn't have to do with 
> InstrumentedList. The problem occurs when beaker pickle.load()s from its 
> cache file (a pickled object in a file).
> I get the following exception (which makes beaker stop loading the session): 
> AttributeError: 'User' object has no attribute '_sa_instance_state'

That means User wasn't mapped when the object was created.  This is one of many 
reasons I've been encouraging declarative as the standard way to go these days, 
so that you can't create a class without it being mapped at once.

> 
> If I try to load the file directly I get the same result.
> 
> I've been trying to google such error but all I get the reference to is that 
> orm.mapper() should be run in the thread or process that is loading the 
> pickled object. I tried loading "manually" (in a python console) my mappers 
> and the trying to unpickle the object without success.

mapper() needs to be run in the process, and should be run in the "main" thread 
before any worker threads are spawned.  It should ideally be part of module 
import, or at the very least a "right after import" initialization step.

The User object itself must be mapped before the original one is ever created, 
before it is ever pickled in the first place.   If it doesn't have a state, it 
means it was not mapped when pickled.

> 
> I cannot (at the moment) include a code example because it is a medium sized 
> pylons project. I know that this was working with version 0.6, with 
> orm.synonym; the main difference is that now I use @hybrid_property and 
> version 0.7.4.

I can't think of a way that @synonym by itself would affect this.   Changing 
back to @synonym in 0.7.4 does what ?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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