[Zope] Help - cannot import zexp
Dieter Maurer
dieter@handshake.de
Sun, 3 Dec 2000 10:41:02 +0100 (CET)
Oleg Broytmann writes:
> .... functions as default parameters to external method functions
> cause import problems ....
> ....
> "Cannot import default_render from module __main__". Oops! What's that?
> The default_render isn't in __main__, sure. I tried to create External
> Method before importing, but this didn't help :(
This is a severe danger of "pickle" and the external method
implementation:
* the implementation does not import the Python source files
but reads them in and executes them.
All functions and classes appear to be defined in the
module "__main__".
* The implementation places the function default arguments
into the ZODB (as a pickle).
* "unpickle" cannot load the corresponding object,
as it imports "__main__" and looks there for the
function -- in vain.
As a rule:
Avoid the use of class of function definitons from
an external method source file for anything that
may be written to the ZODB (or more generally
be pickled; this applies e.g. to session context, too).
This includes created object instances that may
end up as attributes of Zope objects or
function default parameters to external methods.
If you defined such classes or functions in a true
Python module, you should have no problem.
What can you do, if your zexp is valuable?
* put a dummy definition of "default_render" in the
"__main__" module.
You should then be able to import your zexp
and change the problematic external method.
I do not know precisely, what Zope's "__main__"
module is. I expect the "z2.py".
If this is not the case, then a small dummy product
that does "import __main__; __main__.default_render= 0"
should do the trick, whatever "__main__" may be.
Dieter