From 58da38adb6c73289ca67070a17b6f2d29bc056d8 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 7 Feb 2023 17:05:50 +0100 Subject: [PATCH] fix(migration): don't try to add nonexistent tasks as related Discussion: https://community.vikunja.io/t/todoist-migration-fails-after-51-iterations-19-minutes/1137 --- pkg/modules/migration/todoist/todoist.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/modules/migration/todoist/todoist.go b/pkg/modules/migration/todoist/todoist.go index 7719a9ef84..269b5d3de3 100644 --- a/pkg/modules/migration/todoist/todoist.go +++ b/pkg/modules/migration/todoist/todoist.go @@ -369,14 +369,14 @@ func convertTodoistToVikunja(sync *sync, doneItems map[string]*doneItem) (fullVi } // If the parenId of a task is not 0, create a task relation - // We're looping again here to make sure we have seem all tasks before and have them in our map + // We're looping again here to make sure we have seen all tasks before and have them in our map for _, i := range sync.Items { if i.ParentID == "" { continue } if _, exists := tasks[i.ParentID]; !exists { - log.Debugf("[Todoist Migration] Could not find task %s in tasks map while trying to get resolve subtasks for task %s", i.ParentID, i.ID) + log.Debugf("[Todoist Migration] Could not find task %s in tasks map while trying to resolve subtasks for task %s", i.ParentID, i.ID) continue } @@ -385,6 +385,11 @@ func convertTodoistToVikunja(sync *sync, doneItems map[string]*doneItem) (fullVi tasks[i.ParentID].RelatedTasks = make(models.RelatedTaskMap) } + if _, exists := tasks[i.ID]; !exists { + log.Debugf("[Todoist Migration] Could not find task %s in tasks map while trying to add it as subtask", i.ID) + continue + } + tasks[i.ParentID].RelatedTasks[models.RelationKindSubtask] = append(tasks[i.ParentID].RelatedTasks[models.RelationKindSubtask], &tasks[i.ID].Task) // Remove the task from the top level structure, otherwise it is added twice