Skip to content

Commit

Permalink
Check the path when comparing and hashing a keyreference.
Browse files Browse the repository at this point in the history
This makes references more unique, fixing inconsistencies.
Fixes #9
  • Loading branch information
mauritsvanrees committed Mar 18, 2021
1 parent 69a0d73 commit 1c70d13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions five/intid/keyreference.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class KeyReferenceToPersistent(KeyReferenceToPersistent):
"""a zope2ish implementation of keyreferences that unwraps objects
that have Acquisition wrappers
These references compare by _p_oids of the objects they reference.
These references compare by _p_oids of the objects they reference
and by their paths.
@@ cache IConnection as a property and volative attr?
"""
Expand Down Expand Up @@ -154,13 +155,18 @@ def __call__(self):
return self.wrapped_object

def __hash__(self):
# XXX Maybe we should consider to use also other fields for the hash
return hash((self.dbname,
self.object._p_oid,
self.path
))

def __cmp__(self, other):
# XXX This makes no sense on Python 3
if self.key_type_id == other.key_type_id:
return cmp((self.dbname, self.oid), (other.dbname, other.oid))
return cmp((self.dbname, self.oid, self.path), (other.dbname, other.oid, other.path))
return cmp(self.key_type_id, other.key_type_id)

def _get_cmp_keys(self, other):
if self.key_type_id == other.key_type_id:
return (self.dbname, self.oid, self.path), (other.dbname, other.oid, other.path)
return self.key_type_id, other.key_type_id
4 changes: 4 additions & 0 deletions news/9.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Check the path when comparing and hashing a keyreference.
This makes references more unique, fixing inconsistencies.
Fixes `issue 9 <https://github.com/plone/five.intid/issues/9>`_.
[maurits]

0 comments on commit 1c70d13

Please sign in to comment.