Sotring __of__(self) wrapped Objects OK? (was Re: [Zope-dev] Storing references ... accross requests)

Dieter Maurer dieter at handshake.de
Sat Jun 19 04:42:48 EDT 2004


Dario Lopez-Kästen wrote at 2004-6-17 11:01 +0200:
>[ resend - never got to the list ]

Zope's mailing lists currently seem to have problems...
Traffic volume is down to a trickle, at least as seen from here...

> ...
>    class Person(Acquisition.Implicit):
>       def __init__(self data):
>           ...
>
>    PersonObject = Person(data).__of__(self)
>    return PersonObject
>
>If I want to pickle, store and later reuse PersonObject, I suspect that
>this also creates a similar to my original one, where I wanted to store
>ZODB-references in the PersonObject.
>
>
>So should I, when pickling and storing the PersonObject, store
>
>   PersonObject.aq_base
>
>rather than just PersonObject?

You cannot pickle acquisition wrappers, it simply will not work.


The current ZODB code allows you to store wrapped objects as
attributes of persistent objects. It catches the resulting
pickling exception, unwraps the object and tries again.


Whether or not you unwrap yourself or let the ZODB do it:
you loose the acquisition context. Later when you access
your object again (load it), you must rewrap the object.
When the object is stored as an attribute of a persistent
object this rewrapping happens automatically -- but
usually not with the original context!

-- 
Dieter



More information about the Zope-Dev mailing list