[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/keyreference/ Fixed
key-reference bug. Key references for persistent objects didn't
Jim Fulton
jim at zope.com
Mon Jun 20 11:31:55 EDT 2005
Log message for revision 30863:
Fixed key-reference bug. Key references for persistent objects didn't
take the database into account.
Changed:
U Zope3/trunk/src/zope/app/keyreference/persistent.py
U Zope3/trunk/src/zope/app/keyreference/tests.py
-=-
Modified: Zope3/trunk/src/zope/app/keyreference/persistent.py
===================================================================
--- Zope3/trunk/src/zope/app/keyreference/persistent.py 2005-06-20 14:32:05 UTC (rev 30862)
+++ Zope3/trunk/src/zope/app/keyreference/persistent.py 2005-06-20 15:31:55 UTC (rev 30863)
@@ -48,11 +48,16 @@
return self.object
def __hash__(self):
- return hash(self.object._p_oid)
+ return hash((self.object._p_jar.db().database_name,
+ self.object._p_oid,
+ ))
def __cmp__(self, other):
if self.key_type_id == other.key_type_id:
- return cmp(self.object._p_oid, other.object._p_oid)
+ return cmp(
+ (self.object._p_jar.db().database_name, self.object._p_oid),
+ (other.object._p_jar.db().database_name, other.object._p_oid),
+ )
return cmp(self.key_type_id, other.key_type_id)
Modified: Zope3/trunk/src/zope/app/keyreference/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/keyreference/tests.py 2005-06-20 14:32:05 UTC (rev 30862)
+++ Zope3/trunk/src/zope/app/keyreference/tests.py 2005-06-20 15:31:55 UTC (rev 30863)
@@ -17,10 +17,43 @@
"""
import unittest
+def test_multi_databases():
+ """
+ >>> from ZODB.tests.util import DB
+ >>> import transaction
+ >>> from BTrees.OOBTree import OOBucket
+
+ >>> databases = {}
+
+ >>> db1 = DB(databases=databases, database_name='1')
+ >>> db2 = DB(databases=databases, database_name='2')
+
+ >>> conn1 = db1.open()
+ >>> conn1.root()['ob'] = OOBucket()
+
+ >>> conn2 = conn1.get_connection('2')
+ >>> conn2.root()['ob'] = OOBucket()
+
+ >>> conn1.root()['ob']._p_oid == conn2.root()['ob']._p_oid
+ True
+
+ >>> transaction.commit()
+
+ >>> from zope.app.keyreference.persistent import KeyReferenceToPersistent
+
+ >>> key1 = KeyReferenceToPersistent(conn1.root()['ob'])
+ >>> key2 = KeyReferenceToPersistent(conn2.root()['ob'])
+
+ >>> key1 != key2, key2 > key1, hash(key1) != hash(key2)
+ (True, True, True)
+
+"""
+
def test_suite():
from zope.testing import doctest
return unittest.TestSuite((
doctest.DocFileSuite('persistent.txt'),
+ doctest.DocTestSuite(),
))
if __name__ == '__main__':
More information about the Zope3-Checkins
mailing list