active_record_proxy_adapters 0.1.6 → 0.1.7

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: 0650c0793e1af3d7f06f1da1708cc590942468daca491353b57a74575926a5e2
4
- data.tar.gz: 44cd716171d8a8d2d430ac8ae3780f54634ecdf1ae1014ca09720f9fef95bf5b
3
+ metadata.gz: 7644e3cfd1692bbfdbb0bed3e8f92e890599c1c5ad9eb98e76382d49799fe4df
4
+ data.tar.gz: 9476ebb441475da928efd5e2cfdbe46d40cca195f44817a3fa8c9af7bf649483
5
5
  SHA512:
6
- metadata.gz: 68b00c13361168d78b70752002443988132725b013330d1e1161277f73c1a808f0153e76e6fb397bc7dd23c9bc8ba108a6c99ec3bdfc60d45f59a2c47902f693
7
- data.tar.gz: a2bb48e98f0a57bb4f4546ca5bf821be670205a50a0b2ec439a79c98e3db1e43c28b63fe90c7d5849ba0ae048b4b20300658ce7fee62dd874e345c9ac50a0e86
6
+ metadata.gz: 845fc0f94284a9a4835533ef9a47a10805c5fb6591fd3e71201b384a9c8dda4e9b6fe13cfd6e7ba55d72dfea0845d8e338bcf64bc52873c207e4a0da9f5081a2
7
+ data.tar.gz: d660b61a37f6a356df0a1bd44d66e3b5a642e8f4c5e60ce7126da2ea6c789eeb523e83d565aa343d59bbf651710e93d7a3f445901ea390e135213b557dc8b214
@@ -65,6 +65,22 @@ module ActiveRecordProxyAdapters
65
65
  delegate :connection_handler, to: :connection_class
66
66
  delegate :reading_role, :writing_role, to: :active_record_context
67
67
 
68
+ # We need to call .verify! to ensure `configure_connection` is called on the instance before attempting to use it.
69
+ # This is necessary because the connection may have been lazily initialized and is an unintended side effect from a
70
+ # change in Rails to defer connection verification: https://github.com/rails/rails/pull/44576
71
+ # verify! cannot be called before the object is initialized and because of how the proxy hooks into the connection
72
+ # instance, it has to be done lazily (hence the memoization). Ideally, we shouldn't have to worry about this at all
73
+ # But there is tight coupling between methods in ActiveRecord::ConnectionAdapters::AbstractAdapter and
74
+ # its descendants which will require significant refactoring to be decoupled.
75
+ # See https://github.com/rails/rails/issues/51780
76
+ def verified_primary_connection
77
+ @verified_primary_connection ||= begin
78
+ connected_to(role: writing_role) { primary_connection.verify! }
79
+
80
+ primary_connection
81
+ end
82
+ end
83
+
68
84
  def replica_pool_unavailable?
69
85
  !replica_pool
70
86
  end
@@ -135,7 +151,8 @@ module ActiveRecordProxyAdapters
135
151
  end
136
152
 
137
153
  def connection_for(role, sql_string)
138
- connection = primary_connection if role == writing_role || replica_pool_unavailable?
154
+ connection = verified_primary_connection if role == writing_role || replica_pool_unavailable?
155
+
139
156
  connection ||= checkout_replica_connection
140
157
 
141
158
  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.1.6"
4
+ VERSION = "0.1.7"
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.1.6
4
+ version: 0.1.7
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