Skip to content

Commit

Permalink
Create instance actor if it hasn't been properly seeded (mastodon#15693)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ClearlyClaire committed Jan 28, 2022
1 parent 07042a0 commit 24dee67
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/instance_actors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def show
private

def set_account
@account = Account.find(-99)
@account = Account.representative
end

def restrict_fields_to
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/account_finder_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def find_remote!(username, domain)

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)
Expand Down

0 comments on commit 24dee67

Please sign in to comment.