From e8103e49f2af79ef3854518fa8101828638768a7 Mon Sep 17 00:00:00 2001 From: viralpraxis Date: Sun, 24 Aug 2025 01:04:29 +0400 Subject: [PATCH] Silence `_perform` method redefinition warning I'd like to get rid of this noisy warning: ```shell sentry-rails-5.26.0/lib/sentry/rails/background_worker.rb:5: warning: method redefined; discarding old _perform sentry-ruby-5.26.0/lib/sentry/background_worker.rb:74: warning: previous definition of _perform was here ``` #skip-changelog # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Sun Aug 24 01:04:29 2025 +0400 # # On branch silence-perform-method-redefinition-warning # Changes to be committed: # modified: lib/sentry/rails/background_worker.rb # --- .../lib/sentry/rails/background_worker.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sentry-rails/lib/sentry/rails/background_worker.rb b/sentry-rails/lib/sentry/rails/background_worker.rb index 2c0cc7a71..36c362e36 100644 --- a/sentry-rails/lib/sentry/rails/background_worker.rb +++ b/sentry-rails/lib/sentry/rails/background_worker.rb @@ -2,14 +2,18 @@ module Sentry class BackgroundWorker - def _perform(&block) - block.call - ensure - # some applications have partial or even no AR connection - if ActiveRecord::Base.connected? - # make sure the background worker returns AR connection if it accidentally acquire one during serialization - ActiveRecord::Base.connection_pool.release_connection + module ActiveRecordConnectionPatch + def _perform(&block) + super(&block) + ensure + # some applications have partial or even no AR connection + if ActiveRecord::Base.connected? + # make sure the background worker returns AR connection if it accidentally acquire one during serialization + ActiveRecord::Base.connection_pool.release_connection + end end end end end + +Sentry::BackgroundWorker.prepend(Sentry::BackgroundWorker::ActiveRecordConnectionPatch)