[ZODB-Dev] Inconsistent use of ConflictError
JohnD.Heintz
JohnD.Heintz
Thu, 16 Aug 2001 13:48:51 -0500
Hear, hear!!
John
On Thursday 16 August 2001 13:31, Greg Ward wrote:
> This doesn't bother me much anymore now that we're not seeing
> ConflictError in practice (thanks to Connection.sync()), but it still
> bugs me that ZODB is inconsistent in how it uses ConflictError.
>
> In particular, ConflictError appears to be raised in no fewer than 6
> different ways throughout the ZODB/ZEO code (ignoring trivial
> differences like "raise ConflictError" vs. "raise
> POSException.ConflictError"):
>
> raise ConflictError, `oid`
>
> raise ConflictError(`oid`, `object.__class__`)
>
> raise ConflictError, "transaction already invalidated"
>
> raise POSException.ConflictError
>
> raise POSException.ConflictError, (serial, oserial)
>
> raise POSException.ConflictError(
> 'serial number mismatch (was: %s, has: %s)' %
> (utils.U64(oserial), utils.U64(serial)))
>
> Do a recursive grep for "raise.*ConflictError" in StandaloneZODB to see
> for yourself.
>
> This inconsistency makes it pretty much impossible to do anything with
> the exception value; from an API point of view, all of the above might
> as well be a bare "raise ConflictError".
>
> Proposal:
> * give ConflictError an actual interface, ie. some attributes,
> a constructor with keyword arguments, and a __str__() to format
> the error meaningfully
> * fix all occurences of "raise ConflictError" to conform to
> the new interface
>
> Here's a strawman class definition:
>
> class ConflictError(TransactionError):
> """
>
> Instance attributes:
> oid : string
> the OID (8-byte packed string) of the object in conflict
> klass_name : string
> the fully-qualified name of that object's class
> message : string
> a human-readable explanation of the error
> serials : (???, ???)
> pair of mystery objects -- I have no idea what these are,
> I'm just including them because bsddb3Storage/*.py want
> to provide this info
>
> """
>
> def __init__(self, message=3DNone,
> oid=3DNone, klass_name=3DNone, serials=3DNone):
> # message would default to something like
> # "database conflict error"
>
> def __str__ (self):
> return self.message # with some or all of oid, klass_name, a=
nd
> # serials pasted on in a meaningful way
>
> Hmmm, the ConflictError docstring should mention that conflicts can
> occur on read as well.
>
> Thoughts?
>
> Greg
--=20
=2E . . . . . . . . . . . . . . . . . . . . . . .
John D. Heintz | Senior Engineer
1016 La Posada Dr. | Suite 240 | Austin TX 78752
T 512.633.1198 | jheintz@isogen.com
w w w . d a t a c h a n n e l . c o m