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:
parent
cb714c3687
commit
5742344024
4 changed files with 13 additions and 3 deletions
|
@ -19,7 +19,7 @@ module ActiveRecord
|
||||||
execute(sql, name).to_a
|
execute(sql, name).to_a
|
||||||
end
|
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
|
private_constant :READ_QUERY
|
||||||
|
|
||||||
def write_query?(sql) # :nodoc:
|
def write_query?(sql) # :nodoc:
|
||||||
|
|
|
@ -67,7 +67,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
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
|
private_constant :READ_QUERY
|
||||||
|
|
||||||
def write_query?(sql) # :nodoc:
|
def write_query?(sql) # :nodoc:
|
||||||
|
|
|
@ -209,7 +209,7 @@ module ActiveRecord
|
||||||
# DATABASE STATEMENTS ======================================
|
# 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
|
private_constant :READ_QUERY
|
||||||
|
|
||||||
def write_query?(sql) # :nodoc:
|
def write_query?(sql) # :nodoc:
|
||||||
|
|
|
@ -1538,4 +1538,14 @@ class BasicsTest < ActiveRecord::TestCase
|
||||||
assert_queries(2) { Bird.where(name: "Bluejay").explain }
|
assert_queries(2) { Bird.where(name: "Bluejay").explain }
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue