Improved error reporting when deserializing a non-existent record #685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DelayedJob raises an overly generic
Delayed::DeserializationError
when it tries to load a serialized record that does not exist in the DB.This situation can come to be because of a serialization error, or because the record has been deleted since the job was enqueued.
The error is raised because the default YAML behaviour of loading an object is patched to call
klass.find(id)
if the serialized object comes from a recognized persistence library (e.g. ActiveRecord).There have already been discussions about this behaviour: #231, #282 and #296.
It seems like the DJ leads have a strong opinion on this design decision, and no patch has been merged in yet.
I'm not here to argue with the current behaviour and its implications and side effects, but I think we can do something about the error messages to make it clearer what is going on. At the moment DJ is catching the correct errors (e.g.
ActiveRecord::RecordNotFound
), but it's also completely discarding any information that comes with them.This PR adds more descriptive error messages, borrowing from what has already been done here.