[Zope] "can't pickle instancemethod objects" in testcase

Andreas Jung lists at zopyx.com
Mon Jan 7 13:03:20 EST 2008



--On 7. Januar 2008 18:29:50 +0000 Peter Bengtsson <peter at fry-it.com> wrote:

> My code works fine in normal running zope but not when run as a testcase
> (I'm not using bin/zopectl test if that matters) I get the following
> error.
> I feel guilty since I've got this line in my code:
> transaction.get().commit()  (Expense.py#4458)
>
> I remember having come across this error before but can't remember what
> the solution was.
>
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>    File
> "/home/peterbe/zope/zope285/lib/python/Testing/ZopeTestCase/profiler.py",
> line 98, in __call__
>      testMethod()
>    File "testExpenses2.py", line 81, in test_uploadPhotos
>      eids = context.uploadExpenseFiles(files)
>    File "/home/peterbe/zope/zope285/Products/MExpenses/Expense.py", line
> 4458, in uploadExpenseFiles
>      transaction.get().commit()
>    File "lib/python/transaction/_transaction.py", line 381, in commit
>    File "lib/python/transaction/_transaction.py", line 379, in commit
>    File "lib/python/transaction/_transaction.py", line 424, in
> _commitResources
>    File "/home/peterbe/zope/zope285/lib/python/ZODB/Connection.py", line
> 462, in commit
>      self._commit(transaction)
>    File "/home/peterbe/zope/zope285/lib/python/ZODB/Connection.py", line
> 503, in _commit
>      self._store_objects(ObjectWriter(obj), transaction)
>    File "/home/peterbe/zope/zope285/lib/python/ZODB/Connection.py", line
> 525, in _store_objects
>      p = writer.serialize(obj)  # This calls __getstate__ of obj
>    File "/home/peterbe/zope/zope285/lib/python/ZODB/serialize.py", line
> 330, in serialize
>      return self._dump(meta, obj.__getstate__())
>    File "/home/peterbe/zope/zope285/lib/python/ZODB/serialize.py", line
> 339, in _dump
>      self._p.dump(state)
>    File "copy_reg.py", line 69, in _reduce_ex
>      raise TypeError, "can't pickle %s objects" % base.__name__
> TypeError: can't pickle instancemethod objects

Well, this error is self-speaking :-)

The standard solution for figuring out the related property/attr keeping 
the instancemethod is: pdb. Look at the object or its __dict__ and check 
what is
inside or think about your code where you might be assigning a method 
somewhere.

-aj


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope/attachments/20080107/7dc7ee17/attachment.bin


More information about the Zope mailing list