From c45ad112a21df6d3e484785401ce36dd2fd66cce Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 4 Apr 2023 11:24:59 +0200 Subject: [PATCH] fix(migration): don't try to fetch task details of tasks whose projects are deleted --- pkg/modules/migration/todoist/todoist.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/modules/migration/todoist/todoist.go b/pkg/modules/migration/todoist/todoist.go index e5718e7e484..c02afd59639 100644 --- a/pkg/modules/migration/todoist/todoist.go +++ b/pkg/modules/migration/todoist/todoist.go @@ -581,6 +581,14 @@ func (m *Migration) Migrate(u *user.User) (err error) { }) for _, i := range completedSyncResponse.Items { + + // Don't try to fetch task details from deleted projects (that will fail anyway) + _, hasProject := completedSyncResponse.Projects[i.ProjectID] + if hasProject && completedSyncResponse.Projects[i.ProjectID].IsDeleted { + log.Debugf("[Todoist Migration] Not fetching task details from task %s because its project (%s) is deleted already.", i.TaskID, i.ProjectID) + continue + } + if _, has := doneItems[i.TaskID]; has { // Only set the newest completion date continue @@ -599,6 +607,9 @@ func (m *Migration) Migrate(u *user.User) (err error) { if resp.StatusCode == http.StatusNotFound { // Done items of deleted projects may show up here but since the project is already deleted // we can't show them individually and the api returns a 404. + buf := bytes.Buffer{} + _, _ = buf.ReadFrom(resp.Body) + log.Debugf("[Todoist Migration] Could not retrieve task details for task %d: %s", i.TaskID, buf.String()) continue } @@ -607,11 +618,11 @@ func (m *Migration) Migrate(u *user.User) (err error) { if err != nil { return } - log.Debugf("[Todoist Migration] Retrieved full task data for done task %s", i.ID) + log.Debugf("[Todoist Migration] Retrieved full task data for done task %s", i.TaskID) syncResponse.Items = append(syncResponse.Items, doneI.Item) } - if len(completedSyncResponse.Items) < 200 { + if len(completedSyncResponse.Items) < paginationLimit { break } offset++