diff options
author | Eileen Uchitelle <eileencodes@gmail.com> | 2018-12-05 15:36:29 -0500 |
---|---|---|
committer | Eileen Uchitelle <eileencodes@gmail.com> | 2018-12-07 08:53:47 -0500 |
commit | db54afba2e86ec9e45a8feb6e3ed325c99e7c5ed (patch) | |
tree | a41277a318319b5ca5cd2e9b33315ba5699dbfea /activerecord/lib/active_record | |
parent | d9816546494f66e76bd5012a91b872dc2096a06c (diff) | |
download | rails-db54afba2e86ec9e45a8feb6e3ed325c99e7c5ed.tar.gz rails-db54afba2e86ec9e45a8feb6e3ed325c99e7c5ed.tar.bz2 rails-db54afba2e86ec9e45a8feb6e3ed325c99e7c5ed.zip |
Rename error that occurs when writing on a read
I originally named this `StatementInvalid` because that's what we do in
GitHub, but `@tenderlove` pointed out that this means apps can't test
for or explitly rescue this error. `StatementInvalid` is pretty broad so
I've renamed this to `ReadOnlyError`.
Diffstat (limited to 'activerecord/lib/active_record')
4 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb index 43e2f628dc..56f777f3be 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb @@ -29,7 +29,7 @@ module ActiveRecord # Executes the SQL statement in the context of this connection. def execute(sql, name = nil) if preventing_writes? && write_query?(sql) - raise ActiveRecord::StatementInvalid, "Write query attempted while in readonly mode: #{sql}" + raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 2d5b592639..d93c1f449e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -80,7 +80,7 @@ module ActiveRecord # need it specifically, you may want consider the <tt>exec_query</tt> wrapper. def execute(sql, name = nil) if preventing_writes? && write_query?(sql) - raise ActiveRecord::StatementInvalid, "Write query attempted while in readonly mode: #{sql}" + raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 615aa0d83e..dcad230335 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -265,7 +265,7 @@ module ActiveRecord def execute(sql, name = nil) #:nodoc: if preventing_writes? && write_query?(sql) - raise ActiveRecord::StatementInvalid, "Write query attempted while in readonly mode: #{sql}" + raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 7e6d4c1d46..0858af3874 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -49,6 +49,10 @@ module ActiveRecord class ConnectionNotEstablished < ActiveRecordError end + # Raised when a write to the database is attempted on a read only connection. + class ReadOnlyError < ActiveRecordError + end + # Raised when Active Record cannot find a record by given id or set of ids. class RecordNotFound < ActiveRecordError attr_reader :model, :primary_key, :id |