From 6ee352510ac75611c04078efa5584c99ed0e88b9 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 Aug 2018 16:26:42 +1000 Subject: [PATCH] Correctly handle exception --- lib/freedom_patches/active_record_base.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/freedom_patches/active_record_base.rb b/lib/freedom_patches/active_record_base.rb index bcce2b39b97..4f71a4df380 100644 --- a/lib/freedom_patches/active_record_base.rb +++ b/lib/freedom_patches/active_record_base.rb @@ -12,11 +12,10 @@ class ActiveRecord::Base # OR # # find_by(hash) || create_or_find_by(hash) (if we are generally finding) - # def self.find_or_create_by_safe!(hash) begin find_or_create_by!(hash) - rescue PG::UniqueViolation + rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique # try again cause another transaction could have passed by now find_or_create_by!(hash) end