[Zope-dev] pickling limitation in external methods?

Wolf Logan wolf@searchbutton.com
Mon, 3 May 1999 19:01:27 -0700


back in january, i asked a question about this, and jim fulton started to
answer. unfortunately, time pressures were such that i had to abandon that
line of development for a while. well, i'm back now, and with more
information!

can somebody tell my why i might be seeing a problem in using pickles in my
external methods? i have an external method which uses the pickle module to
store and retrieve instances of DateTime (from the mxDateTime module). the
mxDateTime module imports fine, but no longer seems to cooperate with the
pickler. that is, the external method works fine until it tries to unpickle
a DateTime object, whereupon it crashes (with one of the least helpful
tracebacks in recent memory):
-----
Traceback (innermost last):
  File C:\Program Files\WebSite\lib\python\ZPublisher\Publish.py, line 877,
in publish_module
  File C:\Program Files\WebSite\lib\python\ZPublisher\Publish.py, line 590,
in publish
    (Info: /testMethod)
  File C:\Program
Files\WebSite\lib\python\Products\ExternalMethod\ExternalMethod.py, line
254, in __call__
    (Object: CopySource)
    (Info: ((), {}, None))
TypeError: read-only buffer, class
-----

here's the code itself:
-----
def test():
	d = dbConnection.dbConnection()
	r = d.execAndGet("select serial, startDate from myData where
state='started'")
	return '<html><body>%s</body></html>' % (r,)
-----

the dbConnection module proxies a database connection. internally, it
processes results as pickled python objects.

i've isolated the trouble to the DateTime objects. in the execAndGet call
above, everything's fine if the result set doesn't include a DateTime object
(if i remove the "startDate" from the query). if the result set has a
DateTime object, it chokes. they pickle and unpickle just fine and dandy
under "normal" python, but not inside an external method.

we make heavy use of these objects (and the pickling code) in our backend
processing. i've tried replacing the cPickle module that comes with ZOPE
with the one i have in my standard python installation, and it makes no
difference. is there anything anyone can suggest to make this work? would
writing a product (or factory, i can't remember which) be a possible
solution?