Skip to content

Commit edf4ef9

Browse files
committed
Fix config.active_record.destroy_association_async_job configuration
`config.active_record.destroy_association_async_job` should allow applications to specify the job that will be used to destroy associated records in the background for `has_many` associations with the `dependent: :destroy_async` option. That's being ignored, which means the default `ActiveRecord::DestroyAssociationAsyncJob` always destroys records in the background. This change stops ignoring the configuration.
1 parent d9edce6 commit edf4ef9

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

activejob/lib/active_job/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Railtie < Rails::Railtie # :nodoc:
4343
end
4444

4545
ActiveSupport.on_load(:active_record) do
46-
self.destroy_association_async_job = ActiveRecord::DestroyAssociationAsyncJob
46+
self.destroy_association_async_job ||= ActiveRecord::DestroyAssociationAsyncJob
4747
end
4848
end
4949

activerecord/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
* Fix `config.active_record.destroy_association_async_job` configuration
2+
3+
`config.active_record.destroy_association_async_job` should allow
4+
applications to specify the job that will be used to destroy associated
5+
records in the background for `has_many` associations with the
6+
`dependent: :destroy_async` option. Previously, that was ignored, which
7+
meant the default `ActiveRecord::DestroyAssociationAsyncJob` always
8+
destroyed records in the background.
9+
10+
*Nick Holden*
11+
112
* Fix quoting of `ActiveSupport::Duration` and `Rational` numbers in the MySQL adapter.
213

314
*Kevin McPhillips*

railties/test/application/configuration_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,20 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
24442444
assert_equal ActiveRecord::DestroyAssociationAsyncJob, ActiveRecord::Base.destroy_association_async_job
24452445
end
24462446

2447+
test "ActiveRecord::Base.destroy_association_async_job can be configured via config.active_record.destroy_association_job" do
2448+
class ::DummyDestroyAssociationAsyncJob; end
2449+
2450+
app_file "config/environments/test.rb", <<-RUBY
2451+
Rails.application.configure do
2452+
config.active_record.destroy_association_async_job = DummyDestroyAssociationAsyncJob
2453+
end
2454+
RUBY
2455+
2456+
app "test"
2457+
2458+
assert_equal DummyDestroyAssociationAsyncJob, ActiveRecord::Base.destroy_association_async_job
2459+
end
2460+
24472461
test "ActionView::Helpers::FormTagHelper.default_enforce_utf8 is false by default" do
24482462
app "development"
24492463
assert_equal false, ActionView::Helpers::FormTagHelper.default_enforce_utf8

0 commit comments

Comments
 (0)