[Zope-dev] RE: Curious Problem

Guido van Rossum guido@python.org
Fri, 25 Apr 2003 17:10:05 -0400


> I've spent most of the day recreating the setup from scratch, just to rule
> out a python problem.
> 
> I built python 2.1.3 from source, then used that python (renamed
> python2.1.3) to build zope from src.
> 
> I can still run from the command line, but not from zope; same error as
> before.
> 
> One thing I tried was to move the class definition inside the function
> definition
> (how could zope miss it? ;) ) but still no joy.
> 
> I just don't understand why zope even needs to see the class.
> 
> The function reads a record from an rdbms, unpickles and uses a few object
> properties to build a string.  Something in zope itself seems to be
> preventing this.
> 
> Any other thoughts?

Are you sure you understand what you are doing?  Moving a class
definition used by a pickle *inside* a function is a sure recipe for
disaster (the unpickling code can only find classes defined at the
top level in a module).

The error message (SystemError: Failed to import class MyObject from
module __main__) indicates that when the class instance was pickled,
it was in the __main__ module (i.e. in the script that you passed to
the python command line).  There is no way that an external method can
define a class in that module.

It would help if you posted your code.

--Guido van Rossum (home page: http://www.python.org/~guido/)