Skip to content

Commit 8bf495a

Browse files
authored
Merge pull request rails#52577 from n-studio/handle-sqlite-busy-as-deadlock
Handle SQLite3::BusyException to raise ActiveRecord::StatementTimeout
2 parents 24ded03 + 41c547c commit 8bf495a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* SQLite3Adapter: Translate `SQLite3::BusyException` into `ActiveRecord::StatementTimeout`.
2+
3+
*Matthew Nguyen*
4+
15
* Include schema name in `enable_extension` statements in `db/schema.rb`.
26

37
The schema dumper will now include the schema name in generated

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ def translate_exception(exception, message:, sql:, binds:)
662662
InvalidForeignKey.new(message, sql: sql, binds: binds, connection_pool: @pool)
663663
elsif exception.message.match?(/called on a closed database/i)
664664
ConnectionNotEstablished.new(exception, connection_pool: @pool)
665+
elsif exception.is_a?(::SQLite3::BusyException)
666+
StatementTimeout.new(message, sql: sql, binds: binds, connection_pool: @pool)
665667
else
666668
super
667669
end

activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def test_statement_closed
928928
statement.stub(:step, -> { raise ::SQLite3::BusyException.new("busy") }) do
929929
assert_called(statement, :close) do
930930
::SQLite3::Statement.stub(:new, statement) do
931-
error = assert_raises ActiveRecord::StatementInvalid do
931+
error = assert_raises ActiveRecord::StatementTimeout do
932932
@conn.exec_query "select * from statement_test"
933933
end
934934
assert_equal @conn.pool, error.connection_pool

0 commit comments

Comments
 (0)