From 2ead48c1e9f0a91fc2db63f92bb08b7cc6188f5c Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 2 Mar 2025 13:24:55 +0100 Subject: [PATCH] fix(migration): do not crash when relating a task to itself Resolves https://community.vikunja.io/t/vikunja-import-error-tried-to-relate-a-task-with-itself/1105 --- pkg/modules/migration/create_from_structure.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/modules/migration/create_from_structure.go b/pkg/modules/migration/create_from_structure.go index a1bbb4fd8..64c12ffb4 100644 --- a/pkg/modules/migration/create_from_structure.go +++ b/pkg/modules/migration/create_from_structure.go @@ -352,6 +352,13 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas if ttt, exists := tasksByOldID[rt.ID]; exists { taskRel.OtherTaskID = ttt.ID } + + // Add this check to prevent self-relations + if taskRel.TaskID == taskRel.OtherTaskID { + log.Debugf("[creating structure] Skipping invalid self-relation for task %d", taskRel.TaskID) + continue + } + err = taskRel.Create(s, user) if err != nil && !models.IsErrRelationAlreadyExists(err) { return