]> cat aescling's git repositories - mastodon.git/commitdiff
Create instance actor if it hasn't been properly seeded (#15693)
authorClaire <claire.github-309c@sitedethib.com>
Tue, 9 Feb 2021 17:12:54 +0000 (18:12 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Feb 2021 17:12:54 +0000 (18:12 +0100)
An uncommon but somewhat difficult to digagnose issue is dealing with
improperly-seeded databases. In such cases, instance-signed fetches will
fail with a ActiveRecord::RecordNotFound error, usually caught and handled
as generic 404, leading people to think the remote resource itself has not
been found, while it's the local instance actor that does not exist.

This commit changes the code so that failure to find the instance actor
automatically creates a new one, so that improperly-seeded databases do
not cause any issue.

app/controllers/instance_actors_controller.rb
app/models/concerns/account_finder_concern.rb

index 4b074ca19267fcf214e7b058d6a8f988e8ab95b8..b3b5476e2f5a18e25d836b378b54d01a0e7e178b 100644 (file)
@@ -13,7 +13,7 @@ class InstanceActorsController < ApplicationController
   private
 
   def set_account
-    @account = Account.find(-99)
+    @account = Account.representative
   end
 
   def restrict_fields_to
index 04b2c981b17c4aea5317ba47398866bb4ced3170..0dadddad12abf3940e9c91c6ff655b1ecd4b0986 100644 (file)
@@ -14,6 +14,8 @@ module AccountFinderConcern
 
     def representative
       Account.find(-99)
+    rescue ActiveRecord::RecordNotFound
+      Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain)
     end
 
     def find_local(username)