[Zope-dev] Re: Strange serializing error when commiting -> zope.sqlalchemy

Laurence Rowe l at lrowe.co.uk
Tue Jun 3 06:21:25 EDT 2008


Laurence Rowe wrote:
> Hermann Himmelbauer wrote:
>> Am Montag, 2. Juni 2008 20:04 schrieb Hermann Himmelbauer:
>>> Hi,
>>> In my zope3 tests, I set up some basic test data. After that, I'm 
>>> calling
>>> transaction.commit(). However, I get the following traceback:
>>>
>>>
>>> --------------- snip -------------------
>>>   File "copy_reg.py", line 69, in _reduce_ex
>>>     raise TypeError, "can't pickle %s objects" % base.__name__
>>> TypeError: can't pickle module objects
>>> ------------------ snip -------------------
>>
>> I found it by myself: I registered a zope.sqlalchemy related utility, 
>> which stores an engine (self.engine = create_engine(DSN,...)) and a 
>> scoped session (self.Session = scoped_session(sessionmaker...)). These 
>> two objects cannot be serialized, hence the above problem.
>>
>> Now I'm unsure what to do about this problem - is there any code 
>> available that demonstrates how to register SA engines/Sessions as 
>> utilities?
> 
> The simplest solution is to register the Session object as a global 
> utility.

Though that would be quite unnecessary too ;-). If you are ok with one 
global scoped session for your app, then just use `from mymodule import 
Session; session = Session()`.

Laurence



More information about the Zope-Dev mailing list