diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-03-20 16:41:01 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-03-20 16:41:01 -0700 |
commit | d1577cfe3d7f01f2876e3cbe682065012246697c (patch) | |
tree | 0fc5512f74f2c4938c0853d7444fc7112a695c8a /activerecord | |
parent | 38d06478614adcf68a45947cb162c3152e2d7bb1 (diff) | |
parent | 2c8f34995378e4a18711cf5f947e8465227d3748 (diff) | |
download | rails-d1577cfe3d7f01f2876e3cbe682065012246697c.tar.gz rails-d1577cfe3d7f01f2876e3cbe682065012246697c.tar.bz2 rails-d1577cfe3d7f01f2876e3cbe682065012246697c.zip |
Merge branch '3-2-stable' into fredwu-slow_view_loading_fix
* 3-2-stable:
Merge pull request #9802 from newsline/fix-broken-action-missing
Remove bad changelog entry from AR [ci skip]
Wrong exception is occured when raising no translatable exception
Don't crash exception translation w/ nil result attribute.
Conflicts:
actionpack/CHANGELOG.md
Diffstat (limited to 'activerecord')
3 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e55367662b..c0e0bb1dbc 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,10 @@ ## 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. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 8806693397..cbbb195458 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1144,7 +1144,9 @@ module ActiveRecord UNIQUE_VIOLATION = "23505" def translate_exception(exception, message) - case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE) + return exception unless exception.respond_to?(:result) + + case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE) when UNIQUE_VIOLATION RecordNotUnique.new(message, exception) when FOREIGN_KEY_VIOLATION 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| |