Hi,

Today I got a weird error caused by the __cmp__ method of KeyReferenceToPersistent. Unfortunately I couldn't setup a dedicated environment to reproduce the error within a test :(. The only evidence is this traceback:


Traceback (most recent call last):
File "E:\workspace\bopp.ms\src\perse\generic\csv\base.py", line 208, in __call__
   importhandler(configuration)
[...]
File "E:\workspace\bopp.ms\Zope3\src\zope\interface\adapter.py", line 535, in subscribers
   subscription(*objects)
File "E:\workspace\bopp.ms\Zope3\src\zope\app\intid\__init__.py", line 165, in addIntIdSubscriber
   utility.register(key)
File "E:\workspace\bopp.ms\Zope3\src\zope\app\intid\__init__.py", line 112, in register
   if key in self.ids:
File "E:\workspace\bopp.ms\Zope3\src\zope\app\keyreference\persistent.py", line 57, in __cmp__
   return cmp(
AttributeError: 'NoneType' object has no attribute 'db'

I would propose the following fix, but I'm not aware about all possible impacts. Therefore I'm asking for supervision.

class KeyReferenceToPersistent(object):
   [...]
   def _database_name(self):
       try:
           return self.object._p_jar.db().database_name
       except AttributeError:
           return ''

   def __cmp__(self, other):
       if self.key_type_id == other.key_type_id:
           return cmp(
               (self._database_name(),  self.object._p_oid),
               (other._database_name(), other.object._p_oid),
               )

       return cmp(self.key_type_id, other.key_type_id)

If there are no objections, I'm going to commit the fix tomorrow.

Regards,
Dominik

Internet www.perse.ch

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to