FIX: rescue ActiveRecord::RecordInvalid in find_or_create_by_safe! (#6385)

AR uniqueness validation could raise ActiveRecord::RecordInvalid
This commit is contained in:
Kyle Zhao 2018-09-12 09:03:12 +08:00 committed by Sam
parent 02f582eca0
commit f1cb431968
1 changed files with 1 additions and 1 deletions

View File

@ -15,7 +15,7 @@ class ActiveRecord::Base
def self.find_or_create_by_safe!(hash)
begin
find_or_create_by!(hash)
rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique
rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid
# try again cause another transaction could have passed by now
find_or_create_by!(hash)
end