Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #9493 from kennyj/fix_wrong_exception

Wrong exception is occured when raising no translatable exception

Closes #8617
  • Loading branch information...
commit 12cbc57aad153ecd140f917059e11b8d726094b4 2 parents c4f2f5b + e2a4b7a
@rafaelfranca rafaelfranca authored
View
5 activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Fix a problem wrong exception is occured
+ when raising no translatable exception in PostgreSQL.
+
+ *kennyj*
+
* Support PostgreSQL specific column types when using `change_table`.
Fixes #9480.
View
2  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -675,6 +675,8 @@ def postgresql_version
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)
View
6 activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
@@ -250,6 +250,12 @@ def test_distinct_with_nulls
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|
Please sign in to comment.
Something went wrong with that request. Please try again.