diff options
author | Steve Jorgensen <stevej@renewfund.com> | 2012-05-21 09:50:29 -0700 |
---|---|---|
committer | Steve Jorgensen <stevej@renewfund.com> | 2012-07-16 09:55:19 -0700 |
commit | 0d63cda2d70a1e92e71e7c0f6b96c15dc00da117 (patch) | |
tree | 2feffa4e3d6a3ef79a863e517cb340dac438e6cc /activerecord/lib | |
parent | 4a0f6e64d6004b520576e3fae281c9412a61cd8d (diff) | |
download | rails-0d63cda2d70a1e92e71e7c0f6b96c15dc00da117.tar.gz rails-0d63cda2d70a1e92e71e7c0f6b96c15dc00da117.tar.bz2 rails-0d63cda2d70a1e92e71e7c0f6b96c15dc00da117.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/lib')
-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 a57a532ba2..b7f64dba18 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1381,7 +1381,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 |