From f1cb4319686ce653ad9a6477c8b59c05a67b95ae Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Wed, 12 Sep 2018 09:03:12 +0800 Subject: [PATCH] FIX: rescue ActiveRecord::RecordInvalid in find_or_create_by_safe! (#6385) AR uniqueness validation could raise ActiveRecord::RecordInvalid --- lib/freedom_patches/active_record_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/freedom_patches/active_record_base.rb b/lib/freedom_patches/active_record_base.rb index 4f71a4df380..39687ce2aa3 100644 --- a/lib/freedom_patches/active_record_base.rb +++ b/lib/freedom_patches/active_record_base.rb @@ -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