active_record_proxy_adapters 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2af4688cfe39f70ecd6e984f379b9af4a0bc72970e753393fc23d491b0471a35
4
- data.tar.gz: e18681c7b4ed95185bdfa2bd36121c438b113d592223b8cf3838848e530dfd7a
3
+ metadata.gz: fb04343dd0cca68ac16cbea842d12bc6c85b399883d132cf6b41c82623eb297f
4
+ data.tar.gz: 684848e566a132de37149d5873619b18a5a671cf7e86d3c09dd4b43d1d36c02e
5
5
  SHA512:
6
- metadata.gz: 6e0b74329b3de7b75b990fb80ce09b848e605f43b0adbb91f21eed1f01009849f0de2fe8184a21736f5b4515a2f0b71c1a5287fe81aa0e0a189f07dd789dac9e
7
- data.tar.gz: 17ff6ee897897fdcbb3b0d2c16bf1c17cd84f6168cb0015ed3c17de90796fb988e82995835f82585d026db0f842cd020fcfe5d2c5c05c70606ff00407742b0bc
6
+ metadata.gz: c61315b442612b8ac1d28c13dd4d2bf70f7862b1cad438c3603693bec744f73c54dd031bf99da16863ed5caf171def7210f35274735077652799ab4a31c643a8
7
+ data.tar.gz: 7264ea8bdcfb2e58bd1fa1e61498f97503b9694a9b38ac9d04828b200756d476711085d3528d2b08b260de24d0b8a0f58ecbe10222a0431d4f7a6474d6ec5001
@@ -50,6 +50,22 @@ module ActiveRecordProxyAdapters
50
50
  delegate :connection_handler, to: :connection_class
51
51
  delegate :reading_role, :writing_role, to: :active_record_context
52
52
 
53
+ # We need to call .verify! to ensure `configure_connection` is called on the instance before attempting to use it.
54
+ # This is necessary because the connection may have been lazily initialized and is an unintended side effect from a
55
+ # change in Rails to defer connection verification: https://github.com/rails/rails/pull/44576
56
+ # verify! cannot be called before the object is initialized and because of how the proxy hooks into the connection
57
+ # instance, it has to be done lazily (hence the memoization). Ideally, we shouldn't have to worry about this at all
58
+ # But there is tight coupling between methods in ActiveRecord::ConnectionAdapters::AbstractAdapter and
59
+ # its descendants which will require significant refactoring to be decoupled.
60
+ # See https://github.com/rails/rails/issues/51780
61
+ def verified_primary_connection
62
+ @verified_primary_connection ||= begin
63
+ connected_to(role: writing_role) { primary_connection.verify! }
64
+
65
+ primary_connection
66
+ end
67
+ end
68
+
53
69
  def replica_pool_unavailable?
54
70
  !replica_pool
55
71
  end
@@ -120,7 +136,8 @@ module ActiveRecordProxyAdapters
120
136
  end
121
137
 
122
138
  def connection_for(role, sql_string)
123
- connection = primary_connection if role == writing_role || replica_pool_unavailable?
139
+ connection = verified_primary_connection if role == writing_role || replica_pool_unavailable?
140
+
124
141
  connection ||= checkout_replica_connection
125
142
 
126
143
  result = connected_to(role:) { yield connection }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordProxyAdapters
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_proxy_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Cruz
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-25 00:00:00.000000000 Z
10
+ date: 2025-03-04 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord