]> cat aescling's git repositories - mastodon.git/commitdiff
Wrong exception class: ActiveRecord::RecordNotUnique, not PG::UniqueViolation (#7688)
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 31 May 2018 15:22:33 +0000 (17:22 +0200)
committerGitHub <noreply@github.com>
Thu, 31 May 2018 15:22:33 +0000 (17:22 +0200)
* Wrong exception class: ActiveRecord::RecordNotUnique, not PG::UniqueViolation

It's completely not obvious but PG::UniqueViolation is just a string inside the exception message, not the actual class of the exception

* Favourite does not have target_account_id

db/migrate/20180528141303_fix_accounts_unique_index.rb

index e949436dc137c3e257e133e4e707febdcecfb4fb..96cee37f9cba16c0b24f8777aca210888641836f 100644 (file)
@@ -73,15 +73,17 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2]
       klass.where(account_id: duplicate_account.id).find_each do |record|
         begin
           record.update_attribute(:account_id, main_account.id)
-        rescue PG::UniqueViolation
+        rescue ActiveRecord::RecordNotUnique
           next
         end
       end
+    end
 
+    [Follow, FollowRequest, Block, Mute].each do |klass|
       klass.where(target_account_id: duplicate_account.id).find_each do |record|
         begin
           record.update_attribute(:target_account_id, main_account.id)
-        rescue PG::UniqueViolation
+        rescue ActiveRecord::RecordNotUnique
           next
         end
       end