[Zope] Should lambda method be legal or not?
Dieter Maurer
dieter@handshake.de
Mon, 24 Jun 2002 22:08:47 +0200
Terry Hancock writes:
> I ran across this limitation in part of a product design.
> ...
> class MyFolder(OFS.Folder.Folder):
> ...
> def manage_addMyFolder(self, id, title='', REQUEST=None):
> ...
> ob.mymethod = lambda: 2
> ...
> ....
> Until I restart.
>
> Then, an attempt to view the contents of the folder containing
> MyFolder (i.e. not MyFolder itself, but its parent), yields the
> following traceback:
>
> Failed to import class from module __main__
> File /usr/local/narya/z2.5.1/lib/python/ZODB/Connection.py, line 472,
> in setstate
> SystemError: (see above)
ZODB content is the serialized (pickled) state of the objects.
For security reasons, pickle refuses to serialize code. Instead,
it just stores the module and name of code/function objects.
When loaded later again, the name is imported from the remembered
module. As you can see, there are a number of (well documented ;-))
restrictions: functions/classes must be named and defined in the
global namespace of the defining module.
Dieter