[Zope] PersistentMapping is confusing

Paul Winkler slinkp23@yahoo.com
Tue, 13 Nov 2001 15:49:13 -0500


In my Product, I store some data in a PersistentMapping.  I wanted to
directly store references to other Zope objects. This behaves
strangely: objects accessed via this PersistentMapping are fine until
zope restarts. After restart, if I try to retrieve objects from the
PersistentMapping, I get:

Error Type: AttributeError
Error Value: get

As a workaround, I store the ID of the desired object in my
PersistentMapping as a string and then use getattr to retrieve the
object later. This works fine. But it's more work and I don't
understand why it's necessary. Apparently, you can't directly store
ZODB object references in a PersistentMapping.

Is this expected behavior, or a bug? It seems very un-pythonic to me,
and I see no mention of this behavior in the DevGuide or anywhere else
that I've looked.

To reproduce this bug/feature, I've created a very stripped-down product
that's available here:
http://www.slinkp.com/weirdness.zip

To try it:

You need PageTemplates installed.

Unzip weirdness.zip in your Products directory.

In a scratch folder, add a WeirdnessDemo from the management interface.

Click on the new WeirdnessDemo.

Both the links displayed work fine, right?

Now add an image using the form provided.

Both the links still work fine, right?

Now restart Zope.

Go back to the WeirdnessDemo object.

The first link still works, the second one gives an AttributeError.

-- 

paul winkler
home:  http://www.slinkp.com
music: http://www.reacharms.com
calendars: http://www.calendargalaxy.com