Skip to content

Commit

Permalink
Cherry-pick #e2a4b7a that resolves postgres fail
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigues committed Mar 19, 2013
1 parent 4886991 commit 45f735b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 45f735b

Please sign in to comment.