diff options
author | Steve Jorgensen <stevej@renewfund.com> | 2012-05-21 09:50:29 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2013-03-20 10:09:54 +0000 |
commit | be913c3964069fa9ff7c8a615e06705e3a6ec435 (patch) | |
tree | 60d25e13663a30584a417959a0e365b2a87ecfe3 /activerecord | |
parent | 517060ab59c383f912c1be838a6d36afb128288f (diff) | |
download | rails-be913c3964069fa9ff7c8a615e06705e3a6ec435.tar.gz rails-be913c3964069fa9ff7c8a615e06705e3a6ec435.tar.bz2 rails-be913c3964069fa9ff7c8a615e06705e3a6ec435.zip |
Don't crash exception translation w/ nil result attribute.
Exception.result is nil when attempting a query after PostgreSQL
disconnect, resulting in new exception:
NoMethodError: undefined method `error_field' for nil:NilClass
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 8806693397..f01dcec7be 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1144,7 +1144,7 @@ module ActiveRecord UNIQUE_VIOLATION = "23505" def translate_exception(exception, message) - case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE) + case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE) when UNIQUE_VIOLATION RecordNotUnique.new(message, exception) when FOREIGN_KEY_VIOLATION |