Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Don't error when populating MovedTo if account not found #2741

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/db/bundb/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,13 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou
}

if account.MovedTo == nil && account.MovedToURI != "" {
// Account movedTo is not set, fetch from database.
// Account movedTo is not set, try to fetch from database,
// but only error on real errors since this field is optional.
account.MovedTo, err = a.state.DB.GetAccountByURI(
gtscontext.SetBarebones(ctx),
account.MovedToURI,
)
if err != nil {
if err != nil && !errors.Is(err, db.ErrNoEntries) {
errs.Appendf("error populating moved to account: %w", err)
}
}
Expand Down
11 changes: 11 additions & 0 deletions internal/db/bundb/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ func (suite *AccountTestSuite) TestCountAccountPinnedNothingPinned() {
suite.Equal(pinned, 0) // This account has nothing pinned.
}

func (suite *AccountTestSuite) TestPopulateAccountWithUnknownMovedToURI() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_1"]

// Set test account MovedToURI to something we don't have in the database.
// We should not get an error when populating.
testAccount.MovedToURI = "https://unknown-instance.example.org/users/someone_we_dont_know"
err := suite.db.PopulateAccount(context.Background(), testAccount)
suite.NoError(err)
}

func TestAccountTestSuite(t *testing.T) {
suite.Run(t, new(AccountTestSuite))
}