Skip to content
Browse files

Cherry-pick #e2a4b7a that resolves postgres fail

  • Loading branch information...
1 parent 4886991 commit 45f735bdd20ce8e13ce54c9329b9d5a43d5dc364 @rodrigues rodrigues committed
View
5 activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 3.2.13 (Feb 17, 2013) ##
+* Fix a problem wrong exception is occured
+ when raising no translatable exception in PostgreSQL.
+
+ *kennyj*
+
* Reverted 921a296a3390192a71abeec6d9a035cc6d1865c8, 'Quote numeric values
compared to string columns.' This caused several regressions.
View
4 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1144,7 +1144,9 @@ def postgresql_version
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
View
6 activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
@@ -188,6 +188,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|

0 comments on commit 45f735b

Please sign in to comment.
Something went wrong with that request. Please try again.