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

Peter Bengtsson peter at fry-it.com
Mon Jan 7 14:17:06 EST 2008



Andreas Jung wrote:
> 
> 
> --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.
> 
Damn it! Not the answer I was hoping for. I was hoping for something 
simpler and more obvious :)

What object do you suggest I inspect in the debugger then? I don't know 
how the ZODB figures out what it needs to save.

-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list