<p></p>
<p dir="auto">I'm just coming back to this one, and perhaps there might be a way forward. The <a href="https://edgeapi.rubyonrails.org/classes/ActiveJob/Exceptions/ClassMethods.html#method-i-discard_on" rel="nofollow">API docs show</a> that <code class="notranslate">discard_on</code> can take a block, which allows us to access both the error and the job. So could we use that to only discard jobs if it is an ActiveJob::DeserializationError, but only when that's wrapping an ActiveRecord::RecordNotFound error (and not e.g. connection errors).</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">MailDeliveryJob</span> < <span class="pl-v">ActionMailer</span>::<span class="pl-v">MailDeliveryJob</span>
  <span class="pl-en">discard_on</span> <span class="pl-v">ActiveJob</span>::<span class="pl-v">DeserializationError</span> <span class="pl-k">do</span> |<span class="pl-s1">job</span><span class="pl-kos">,</span> <span class="pl-s1">error</span>|
    <span class="pl-k">unless</span> <span class="pl-s1">error</span><span class="pl-kos">.</span><span class="pl-en">is_a?</span><span class="pl-kos">(</span><span class="pl-v">ActiveRecord</span>::<span class="pl-v">RecordNotFound</span><span class="pl-kos">)</span>
      <span class="pl-s1">job</span><span class="pl-kos">.</span><span class="pl-en">enqueue</span> <span class="pl-pds">wait</span>: <span class="pl-c1">5</span><span class="pl-kos">.</span><span class="pl-en">minutes</span>
  <span class="pl-k">end</span>
<span class="pl-k">end</span></pre></div>
<p dir="auto">We'd certainly need some tests to make sure this works properly!</p>
<p dir="auto">I've also <a href="https://discuss.rubyonrails.org/t/is-discard-on-activejob-deserializationerror-a-footgun/88442" rel="nofollow">asked on the rails mailing list</a> in case anyone else can shed some light on this. It feels like it could be something that applies more widely.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tomhughes/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tomhughes">@tomhughes</a> before I go any further with working on this, how often are you running into this in production? I can't tell how much effort would be worthwhile here.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4323#issuecomment-2593472246">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLNA6CDQBKTMHJ4AARL2K2ICJAVCNFSM6AAAAABVHWWRYCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOJTGQ3TEMRUGY">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLPIOB4ZBRPEJC6UXLT2K2ICJA5CNFSM6AAAAABVHWWRYCWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTU2SU7PM.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4323/c2593472246</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4323#issuecomment-2593472246",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4323#issuecomment-2593472246",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>