about summary refs log tree commit diff
path: root/app/models/concerns
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-02-09 18:12:54 +0100
committerGitHub <noreply@github.com>2021-02-09 18:12:54 +0100
commitacdeb162b8c2e7d036c34690de85dea70277713d (patch)
treede2ae568cf5c57f7db5c5b9620bcbccf504f2bd5 /app/models/concerns
parentacf1842896682674d9ab4d0f87ec04c6174468fa (diff)
Create instance actor if it hasn't been properly seeded (#15693)
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.
Diffstat (limited to 'app/models/concerns')
-rw-r--r--app/models/concerns/account_finder_concern.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb
index 04b2c981b..0dadddad1 100644
--- a/app/models/concerns/account_finder_concern.rb
+++ b/app/models/concerns/account_finder_concern.rb
@@ -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)