[Zope] Problems with list of object references
Dieter Maurer
dieter@handshake.de
Mon, 12 Aug 2002 21:26:25 +0200
Sven Rudolph writes:
> ...
> I wrote a product that buffers a list of objects. The list is created with
> self.LIST = self.restrictedTraverse(ListOfPaths).objectValues['MyOtherProduct']))
> inside a function called "charge_buffer".
>
> This product also has a DTMLFile named "show_list". "show_list" contains:
> <dtml-var LIST>
>
> When I open "show_list" in my browser I can see the list like this:
> [<MyOtherProduct instance at ecdcfa8>, <MyOtherProduct instance at ecdd050>, etc. ]
You should be very careful with this:
Most Zope objects you handle are acquisition wrappers.
These are not persistent (even if the base objects are) and
cannot be stored in ZODB.
When you want to make them persistent, you need to strip down the
wrapper before storing and wrap again on access, something like:
self.LIST= [o.aq_base for o in self.restrictedTraverse(...)...]
def getLIST(self):
return [o.__of__(self) for o in self.LIST]
> ...
> This seems to work very well. When I open "use_list" in my browser I see a list of ids.
> But when I reload "use_list" 3 or 4 times I suddenly get an attribute error for "get", just as if the sequence-item wasn't an object anymore.
I do not understand it.
Instead, you should have gotten an "Unpicklable Error".
> The same thing happens when I refresh my product or restart the server.
Obviously, your objects are not pickled correctly.
I wonder why they did at all.
Dieter