isolator 1.1.2 → 1.2.0

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: a37693d4626a6bb72e14c00562274a1002c557aca0122182f2422be08e225ad8
4
- data.tar.gz: ed49eb36314577217281389ea07d3dcb8c72c30373fd03f6b6609e2d43ea4d99
3
+ metadata.gz: 1c367300194152c4e2d8adb2c9ff4ab37cc66f9e1eab3e5a1d1576b98fb4970b
4
+ data.tar.gz: c132274cc0936d897f2ecfda8d4c1523db73d5a803f5516ed8eb655fda9f9586
5
5
  SHA512:
6
- metadata.gz: e3c11b5f2da9fa95dc4f167b757e5a0dee3466ead28cb458839b1651b8e6db0631f72b9d1bcc0de239f41adb27b3dbd99aab46cf2d3872bcd462c75aa61aa471
7
- data.tar.gz: c9ea41ae4b214da35c3e5c8c53c75c5f8f3b74b620ff5e2f3d1dbfcbb52312f3620ba811829c7a46b82de87cb00420d74b55d1efc7b5a1cd47295ac4eca60afe
6
+ metadata.gz: 8eb94aeb576bb42fe9b267403cde9d6418964db34c111ca23e5a8f415fc85aa936eab2da5647eec2878526e0d5998a6b40e09c68fd55afa5ef5648bb8f66ba12
7
+ data.tar.gz: 6285571a44a18c0d21816d48c7580f1a9a0167fedae5db5d5ff757f1485561bef15798f6781e7b7347fe0d87105931a0fd42560abb6b52f1e3fdb223d58785be
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.2.0 (2025-11-07)
6
+
7
+ - Use `ActiveRecord::Base.lease_connection` instead of `ActiveRecord::Base.connection`, if available. ([@viralpraxis][])
8
+
9
+ - Add ability to limit subtransaction amount. ([@dnamsons][])
10
+
11
+ This feature is disabled by default, opt-in via: `Isolator.config.max_subtransactions_depth = :desired_depth`.
12
+
5
13
  ## 1.1.2 (2025-10-16)
6
14
 
7
15
  - Fix `database_cleaner` support: require `base.rb` explicitly. ([@viralpraxis][])
@@ -161,3 +169,4 @@ This, for example, makes Isolator compatible with Rails multi-database apps.
161
169
  [@tagirahmad]: https://github.com/tagirahmad
162
170
  [@arthurWD]: https://github.com/arthurWD
163
171
  [@joshuay03]: https://github.com/joshuay03
172
+ [@viralpraxis]: https://github.com/viralpraxis
data/README.md CHANGED
@@ -109,6 +109,9 @@ Isolator.configure do |config|
109
109
 
110
110
  # Turn on/off raising exceptions for simultaneous transactions to different databases
111
111
  config.disallow_per_thread_concurrent_transactions = false
112
+
113
+ # Limit the amount of allowed nested transactions
114
+ config.max_subtransactions_depth = 5
112
115
  end
113
116
  ```
114
117
 
@@ -6,7 +6,9 @@ require "database_cleaner/active_record/transaction"
6
6
  Module.new do
7
7
  def start
8
8
  super
9
- connection_id = connection_class.connection.object_id
9
+
10
+ connection_id = connection.object_id
11
+
10
12
  Isolator.set_connection_threshold(
11
13
  Isolator.transactions_threshold(connection_id) + 1,
12
14
  connection_id
@@ -14,12 +16,24 @@ require "database_cleaner/active_record/transaction"
14
16
  end
15
17
 
16
18
  def clean
17
- connection_id = connection_class.connection.object_id
19
+ connection_id = connection.object_id
20
+
18
21
  Isolator.set_connection_threshold(
19
22
  Isolator.transactions_threshold(connection_id) - 1,
20
23
  connection_id
21
24
  )
25
+
22
26
  super
23
27
  end
28
+
29
+ private
30
+
31
+ def connection
32
+ if Gem::Version.new("7.2") <= Gem::Version.new(Rails::VERSION::STRING)
33
+ connection_class.lease_connection
34
+ else
35
+ connection_class.connection
36
+ end
37
+ end
24
38
  end
25
39
  )
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Isolator
4
+ class Configuration
5
+ attr_accessor :max_subtransactions_depth
6
+ end
7
+
8
+ class MaxSubtransactionsExceededError < UnsafeOperationError
9
+ MESSAGE = "Allowed subtransaction amount exceeded"
10
+ end
11
+
12
+ Isolator.on_transaction_begin do |event|
13
+ next if Isolator.config.max_subtransactions_depth.nil?
14
+
15
+ depth = event[:depth]
16
+ next unless (depth - 1) > Isolator.config.max_subtransactions_depth
17
+
18
+ Isolator.notify(exception: MaxSubtransactionsExceededError.new, backtrace: caller)
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Isolator
4
- VERSION = "1.1.2"
4
+ VERSION = "1.2.0"
5
5
  end
data/lib/isolator.rb CHANGED
@@ -263,3 +263,4 @@ require "isolator/database_cleaner_support" if defined?(DatabaseCleaner)
263
263
 
264
264
  # Built-in extensions
265
265
  require "isolator/plugins/concurrent_database_transactions"
266
+ require "isolator/plugins/database_subtransactions"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isolator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-16 00:00:00.000000000 Z
11
+ date: 2025-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sniffer
@@ -318,6 +318,7 @@ files:
318
318
  - lib/isolator/orm_adapters/active_support_transaction_subscriber.rb
319
319
  - lib/isolator/orm_adapters/rom_active_support.rb
320
320
  - lib/isolator/plugins/concurrent_database_transactions.rb
321
+ - lib/isolator/plugins/database_subtransactions.rb
321
322
  - lib/isolator/railtie.rb
322
323
  - lib/isolator/simple_hashie.rb
323
324
  - lib/isolator/version.rb