Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #6397 from kennyj/fix_translate_exception
Browse files Browse the repository at this point in the history
Fix a problem of translate_exception method in a Japanese (non English) environment.
  • Loading branch information
tenderlove authored and rafaelfranca committed Nov 30, 2012
1 parent d7deec3 commit 564e32b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 3.2.10 (unreleased)

* Fix a problem with `translate_exception` method in a non English environment.
Backport of #6397.

*kennyj*

* Fix dirty attribute checks for TimeZoneConversion with nil and blank
datetime attributes. Setting a nil datetime to a blank string should not
result in a change being flagged. Fix #8310 [Backport #8311]
Expand Down
Expand Up @@ -1142,11 +1142,15 @@ def postgresql_version
@connection.server_version
end

# See http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html
FOREIGN_KEY_VIOLATION = "23503"
UNIQUE_VIOLATION = "23505"

def translate_exception(exception, message)
case exception.message
when /duplicate key value violates unique constraint/
case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE)
when UNIQUE_VIOLATION
RecordNotUnique.new(message, exception)
when /violates foreign key constraint/
when FOREIGN_KEY_VIOLATION
InvalidForeignKey.new(message, exception)
else
super
Expand Down

0 comments on commit 564e32b

Please sign in to comment.