Permalink
Browse files

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
  • Loading branch information...
1 parent 4a0f6e6 commit 0d63cda2d70a1e92e71e7c0f6b96c15dc00da117 Steve Jorgensen committed May 21, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
View
2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1381,7 +1381,7 @@ def postgresql_version
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

0 comments on commit 0d63cda

Please sign in to comment.