From c2a5e603c22ed104cfe48f1d93338fea98f8fd23 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 19 Oct 2017 14:47:29 +0800 Subject: [PATCH] Guard `ActionRecord::Base.exec_sql` against a readonly PostgreSQL cluster. --- lib/freedom_patches/active_record_base.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/freedom_patches/active_record_base.rb b/lib/freedom_patches/active_record_base.rb index bd4eb2c1e82..18746093f93 100644 --- a/lib/freedom_patches/active_record_base.rb +++ b/lib/freedom_patches/active_record_base.rb @@ -5,6 +5,8 @@ class ActiveRecord::Base conn = ActiveRecord::Base.connection sql = ActiveRecord::Base.send(:sanitize_sql_array, args) conn.raw_connection.exec(sql) + rescue PG::ReadOnlySqlTransaction + Rails.logger.warn("WARN: PostgreSQL is in a readonly state. Performed a noop") end def self.exec_sql_row_count(*args)