zopefoundation / ZODB

Python object-oriented database
https://zodb-docs.readthedocs.io/
Other
681 stars 92 forks source link

Better POSKeyError handling #206

Open jimfulton opened 6 years ago

jimfulton commented 6 years ago

Dealing with POSKeyErrors is way too painful.

I think there are some things we can do to make this less painful:

jmuchemb commented 6 years ago

When a POSKeyError is encountered when loading object state, include the referring object databsee id in the error and make sure they're displayed when the error is displayed.

IIUC, this is only useful when using multiple ZODB in an application.

Add an option to return a broken object without erroring and still log the error.

I don't understand.

jimfulton commented 6 years ago

On Tue, May 29, 2018 at 5:25 AM, Julien Muchembled <notifications@github.com

wrote:

When a POSKeyError is encountered when loading object state, include the referring object databsee id in the error and make sure they're displayed when the error is displayed.

IIUC, this is only useful when using multiple ZODB in an application.

Sorry, that should have read: "the referring object's id and database id." Fixed. The main idea here is to figure out what the referring object is.

Add an option to return a broken object without erroring and still log the error.

I don't understand.

Today, POSKetErrors are very hard to deal with because the error occurs at a very low level. Optionally, allowing a broken object to be used elevates these errors to the application level where it's potentially easier to deal with. We want to log the error even if we return a broken object without raising an application exception.

vpelletier commented 6 years ago

I worked on this issue during the sprint today. Here is how far I got:

POSKeyError is raised when the code is trying to fill an existing ghost object. At this point the appliation already thinks it has an instance (ghost state, being un-ghostified), so it's not as straightforward as the usual BrokenObject use-case (where it's the class which does not exist, so not an internal inconsistency of the database).

Intercepting the POSKeyError exception inside ZODB may not let the application progress much, because the replacement instance needs to make hard decisions. A few examples could be:

If the replacement instance cannot take such decision, it will likely just raise an exception, which brings us back to square one.

So my feeling is that the POSKerError should propagate the way it already does, and should be handled by the application (data structure class, ...) as appropriate rather than making ZODB level take the decision for the application.

Discussing with @jimfulton , he said this error is typically reported is when packing: while walking the object tree to find orphan nodes (any non-walked node is an orphan object), references to missing objects completely prevent packing, leading to this exception and preventing the pack from finishing.

In the specific case of pack:

ml31415 commented 2 years ago

I'd vote for better error handling in general. It's not only POSKeyErrors, but also all sorts of zlib.errors or UnpicklingErrors, that might creep into the database over the years and then break packing or object iteration and retrieval.