[Zope-CVS] CVS: Products/AdaptableStorage/zodb - ASConnection.py:1.15
Shane Hathaway
shane@zope.com
Fri, 10 Jan 2003 14:02:19 -0500
Update of /cvs-repository/Products/AdaptableStorage/zodb
In directory cvs.zope.org:/tmp/cvs-serv8857/zodb
Modified Files:
ASConnection.py
Log Message:
Made it safe to re-use OIDs that are no longer in use. OID reuse happens
when using Zope2FS and the user removes an object and later replaces it
with an object by the same name. ASConnection has an easy way to deal with
this: it just minimizes the cache and tries to cache it again.
=== Products/AdaptableStorage/zodb/ASConnection.py 1.14 => 1.15 ===
--- Products/AdaptableStorage/zodb/ASConnection.py:1.14 Mon Jan 6 18:17:55 2003
+++ Products/AdaptableStorage/zodb/ASConnection.py Fri Jan 10 14:02:17 2003
@@ -23,6 +23,7 @@
from ZODB import Persistent
from ZODB.Connection import Connection, StringIO, Unpickler, Pickler, \
ConflictError, ReadConflictError, LOG, ERROR
+from Acquisition import aq_base
from consts import SERIAL0, DEBUG
from mapper_public import IKeyedObjectSystem, SerializationEvent, \
@@ -267,14 +268,24 @@
dump(state)
p=file(1)
s=dbstore(oid,serial,p,version,transaction)
+
# Put the object in the cache before handling the
# response, just in case the response contains the
# serial number for a newly created object
- try: cache[oid]=object
+ try: cache[oid] = object
+ except ValueError:
+ # "Cannot re-register an object under a different
+ # oid". This can happen when the user is working on
+ # the filesystem and creates an object with an ID that
+ # was used recently. Try to fix it by minimizing
+ # the cache and trying again.
+ cache.minimize()
+ cache[oid] = object
except:
- # It could be wrapped.
- if hasattr(object, 'aq_base'):
- cache[oid]=object.aq_base
+ if aq_base(object) is not object:
+ # Yuck, someone tried to store a wrapper. Try to
+ # cache it unwrapped.
+ cache[oid] = aq_base(object)
else:
raise