From b2297e76e37b4e1baa4582ea486fecb270c69a5f Mon Sep 17 00:00:00 2001 From: Ron Shinall <81988008+ron-shinall@users.noreply.github.com> Date: Sat, 9 Mar 2024 07:59:51 -0700 Subject: [PATCH] Addressing Rails Edge breaking change with insert_all --- app/models/solid_cache/entry.rb | 14 +++++++------- test/unit/execution_test.rb | 9 +++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/models/solid_cache/entry.rb b/app/models/solid_cache/entry.rb index c7b401f..a5ef6fa 100644 --- a/app/models/solid_cache/entry.rb +++ b/app/models/solid_cache/entry.rb @@ -70,13 +70,13 @@ def id_range private def upsert_all_no_query_cache(payloads) - insert_all = ActiveRecord::InsertAll.new( - self, - add_key_hash_and_byte_size(payloads), - unique_by: upsert_unique_by, - on_duplicate: :update, - update_only: upsert_update_only - ) + insert_all_args = [ self, + Rails.version >= "7.2" ? connection : nil, + add_key_hash_and_byte_size(payloads) ].compact + options = { unique_by: upsert_unique_by, + on_duplicate: :update, + update_only: upsert_update_only } + insert_all = ActiveRecord::InsertAll.new(*insert_all_args, **options) sql = connection.build_insert_sql(ActiveRecord::InsertAll::Builder.new(insert_all)) message = +"#{self} " diff --git a/test/unit/execution_test.rb b/test/unit/execution_test.rb index 79743ba..a86e8a1 100644 --- a/test/unit/execution_test.rb +++ b/test/unit/execution_test.rb @@ -108,7 +108,7 @@ def test_active_record_instrumention_expiry def test_no_connections_uninstrumented skip if multi_cluster? - ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(:connection).raises(ActiveRecord::StatementInvalid) + ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(connection).raises(ActiveRecord::StatementInvalid) cache = lookup_store(expires_in: 60, active_record_instrumentation: false) @@ -124,7 +124,7 @@ def test_no_connections_uninstrumented def test_no_connections_instrumented skip if multi_cluster? - ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(:connection).raises(ActiveRecord::StatementInvalid) + ActiveRecord::ConnectionAdapters::ConnectionPool.any_instance.stubs(connection).raises(ActiveRecord::StatementInvalid) cache = lookup_store(expires_in: 60) @@ -148,4 +148,9 @@ def report(error, handled:, severity:, context:, source: nil) errors << [ error, { context: context, handled: handled, level: severity, source: source } ] end end + + private + def connection + Rails.version >= "7.2" ? :lease_connection : :connection + end end