[Zope] POSKeyError nightmare

Dieter Maurer dieter at handshake.de
Sun Oct 16 12:32:00 EDT 2005


Kevin Carlson wrote at 2005-10-10 18:37 -0400:
>...
>I'm not sure I understand what you mean by fixing them all as shown 
>above.  You mention loading the object from the ZODB and deleting the 
>broken references, but I'm not sure how to do that.

"fsrefs" tells you the OID of objects containing broken
references.

When you have the OID (as binary value; I think
"fsrefs" tells you the hex value, then can use "hexvalue.decode('hex')"
to get it as binary), you can load the respective object
via

	obj = connection[OID]

You get the connection from an object via "obj._p_jar".


In your case, an "OOBucket" lost some of its references
(that is an easy case -- provided it does not loose all its content).

  You determine the broken keys and delete them:

    for k,v in list(bucket.objectItems()):
      try: v._p_changed = 0 # load the object
      except:
        # broken
	del bucket[k]

  The case becomes very complicated, when the bucket ends
  empty -- an empty bucket would make the (probably) enclosing
  BTree invalid. You would need to fake something to
  keep it non-empty.

    if not bucket: bucket[k] = None # "k" was one of the deleted keys


-- 
Dieter


More information about the Zope mailing list