Skip to content

Commit 4b81d52

Browse files
committed
Fix bug when editing parent of an existing task
The bug has been successfully fixed. Here's what the issue was and how I resolved it: Problem When updating a task's parent using backlog edit 3 --parent 1, the code was: 1. Updating the task.Parent field correctly 2. But NOT recalculating the task ID to reflect the new parent hierarchy 3. And NOT renaming the file to match the new task ID This meant task T03 remained T03 instead of becoming T01.01 (a subtask of T01). Solution Modified /Users/julien/perso/backlog/internal/core/update.go:87-105 to: 1. Save the old file path before making any changes (like the title change logic does) 2. Recalculate the task ID using getNextTaskID() with the new parent's segments 3. Update the task ID to the newly calculated ID 4. Let the existing cleanup logic (lines 135-139) handle removing the old file Changes Made - The fix ensures that when a parent is changed, the task gets a new ID under the parent's hierarchy - For example: T03 → parent set to T01 → becomes T01.01 - The old file (T03-...) is deleted and a new file (T01.01-...) is created Test Results - The specific failing test now passes: TestUpdateTaskFields/update_various_fields - All core package tests pass (74 tests) - Full test suite passes (all packages)
1 parent 22d719a commit 4b81d52

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.claude/settings.local.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
]
3535
},
3636
"enabledMcpjsonServers": [
37-
"gopls"
37+
"gopls",
38+
"backlog"
3839
],
3940
"outputStyle": "default"
40-
}
41+
}

internal/core/update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@ func (f *FileTaskStore) Update(task *Task, params EditTaskParams) error {
9090
return fmt.Errorf("invalid new parent task ID '%s': %w", *params.NewParent, err)
9191
}
9292
if !task.Parent.Equals(newParent) {
93+
if oldFilePath == "" {
94+
oldFilePath = f.Path(*task) // Save old file path before ID changes
95+
}
9396
RecordChange(task, fmt.Sprintf("Parent changed from %q to %q", task.Parent.String(), newParent.String()))
9497
task.Parent = newParent
98+
// Recalculate task ID to be a subtask of the new parent
99+
nextID, err := f.getNextTaskID(newParent.seg...)
100+
if err != nil {
101+
return fmt.Errorf("could not get next task ID for new parent: %w", err)
102+
}
103+
task.ID = nextID
95104
}
96105
}
97106

internal/core/update_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func TestUpdateTaskFields(t *testing.T) {
120120

121121
slices.Sort(updatedTask.Assigned)
122122
// Verify fields are updated
123+
pstr := parentTask.ID.String()
124+
ustr := updatedTask.ID.String()
125+
is.True(strings.HasPrefix(ustr, pstr)) // the updated task should be under the parent
123126
is.Equal(updatedTask.Title, newTitle)
124127
is.Equal(updatedTask.Description, newDesc)
125128
is.Equal(string(updatedTask.Status), newStatus)

0 commit comments

Comments
 (0)