1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

An empty transaction does not raise the ReadOnlyError if preventing writes

BEGIN transaction would cause COMMIT or ROLLBACK, so unless COMMIT and
ROLLBACK aren't treated as write queries as well as BEGIN, the
`ReadOnlyError` would be raised.
This commit is contained in:
Ryuta Kamizono 2018-12-11 20:55:36 +09:00
parent cb714c3687
commit 5742344024
4 changed files with 13 additions and 3 deletions

View file

@ -19,7 +19,7 @@ module ActiveRecord
execute(sql, name).to_a
end
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :explain, :select, :set, :show, :release, :savepoint, :rollback) # :nodoc:
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback) # :nodoc:
private_constant :READ_QUERY
def write_query?(sql) # :nodoc:

View file

@ -67,7 +67,7 @@ module ActiveRecord
end
end
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :explain, :select, :set, :show, :savepoint, :rollback) # :nodoc:
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback) # :nodoc:
private_constant :READ_QUERY
def write_query?(sql) # :nodoc:

View file

@ -209,7 +209,7 @@ module ActiveRecord
# DATABASE STATEMENTS ======================================
#++
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :explain, :select, :pragma, :savepoint, :rollback) # :nodoc:
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin, :commit, :explain, :select, :pragma, :release, :savepoint, :rollback) # :nodoc:
private_constant :READ_QUERY
def write_query?(sql) # :nodoc:

View file

@ -1538,4 +1538,14 @@ class BasicsTest < ActiveRecord::TestCase
assert_queries(2) { Bird.where(name: "Bluejay").explain }
end
end
test "an empty transaction does not raise if preventing writes" do
ActiveRecord::Base.connection.while_preventing_writes do
assert_queries(2, ignore_none: true) do
Bird.transaction do
ActiveRecord::Base.connection.materialize_transactions
end
end
end
end
end