diff options
author | kennyj <kennyj@gmail.com> | 2013-03-01 01:55:20 +0900 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2013-03-20 10:11:07 +0000 |
commit | dc2bc388bc8c6c345337052bf0d60f5243d899d4 (patch) | |
tree | 3f4ec4d6873f1ab94af33fe37701d46e0a43f8cf | |
parent | be913c3964069fa9ff7c8a615e06705e3a6ec435 (diff) | |
download | rails-dc2bc388bc8c6c345337052bf0d60f5243d899d4.tar.gz rails-dc2bc388bc8c6c345337052bf0d60f5243d899d4.tar.bz2 rails-dc2bc388bc8c6c345337052bf0d60f5243d899d4.zip |
Wrong exception is occured when raising no translatable exception
Conflicts:
activerecord/CHANGELOG.md
3 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e55367662b..ebab222b8c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,10 +1,18 @@ ## unreleased ## +* Fix a problem wrong exception is occured + when raising no translatable exception in PostgreSQL. + + *kennyj* + * Resets the postgres search path in the structure.sql after the structure is dumped in order to find schema_migrations table when multiples schemas are used. Fixes #9796. +* Support PostgreSQL specific column types when using `change_table`. + Fixes #9480. + *Juan M. Cuello + Dembskiy Alexander* * Reload the association target if it's stale. `@stale_state` should be nil diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index f01dcec7be..cbbb195458 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1144,6 +1144,8 @@ module ActiveRecord UNIQUE_VIOLATION = "23505" def translate_exception(exception, message) + return exception unless exception.respond_to?(:result) + case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE) when UNIQUE_VIOLATION RecordNotUnique.new(message, exception) diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 0de3786eb8..6c345cd8cc 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -188,6 +188,12 @@ module ActiveRecord assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"]) end + def test_raise_error_when_cannot_translate_exception + assert_raise TypeError do + @connection.send(:log, nil) { @connection.execute(nil) } + end + end + private def insert(ctx, data) binds = data.map { |name, value| |