Is `discard_on ActiveJob::DeserializationError` a footgun?

In the template for ApplicationJob there is the following comment:

# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError

However, ActiveJob::DeserializationError is a wrapper error that covers all errors encountered when deserializing, not just “the object being deserialized doesn’t exist in the database”. For example, it also covers situations such as temporary connection failures to the database (examples of such errors can be found in this unrelated issue).

So if you enable discard_on ActiveJob::DeserializationError and you have a short network outage, all your legitimate pending jobs could be instantly and silently discarded. Which is probably not what you want?

So I have two questions:

  • Should the template be suggesting this discard_on configuration, without highlighting this large pitfall?
  • Is there a better way to configure discard_on, so that it only discards jobs where the object can’t be deserialized because it’s no longer in the db, but without also discarding for other reasons?

I’ve read suggestions about using discard_on ActiveRecord::RecordNotFound instead, but that will catch all ActiveRecord::RecordNotFound raised during the perform method, not just ones encountered during deserialization.