@@ -40,11 +40,11 @@ pub async fn link_parent_task(
4040 tracing:: debug!( old_parent = ?old_parent, "fetched current parent" ) ;
4141
4242 // 2. Remove from old parent if changed
43- if let Some ( old_parent_id) = old_parent {
44- if Some ( old_parent_id) != parent_task_id {
45- remove_from_parent_subtasks ( & mut tx , old_parent_id , task_id ) . await ? ;
46- tracing :: debug! ( old_parent = % old_parent_id, "removed task from old parent's Subtasks" ) ;
47- }
43+ if let Some ( old_parent_id) = old_parent
44+ && Some ( old_parent_id) != parent_task_id
45+ {
46+ remove_from_parent_subtasks ( & mut tx , old_parent_id, task_id ) . await ? ;
47+ tracing :: debug! ( old_parent = %old_parent_id , "removed task from old parent's Subtasks" ) ;
4848 }
4949
5050 // 3. Set new parent (returns true if task exists)
@@ -86,10 +86,10 @@ pub async fn link_subtasks(
8686 let mut tx = pool. begin ( ) . await . context ( "failed to begin transaction" ) ?;
8787
8888 // Validate: can't include parent as subtask (would create mutual reference)
89- if let Some ( current_parent) = get_task_parent ( & mut tx, task_id) . await ? {
90- if subtask_ids. contains ( & current_parent) {
91- anyhow :: bail! ( "cannot set parent as subtask (would create circular reference)" ) ;
92- }
89+ if let Some ( current_parent) = get_task_parent ( & mut tx, task_id) . await ?
90+ && subtask_ids. contains ( & current_parent)
91+ {
92+ anyhow :: bail! ( "cannot set parent as subtask (would create circular reference)" ) ;
9393 }
9494
9595 // 1. Get current subtasks & compute diff
@@ -118,15 +118,15 @@ pub async fn link_subtasks(
118118
119119 // 3. For added subtasks: remove from old parent, set new parent
120120 for subtask_id in & added {
121- if let Some ( old_parent_id) = get_task_parent ( & mut tx, * subtask_id) . await ? {
122- if old_parent_id != task_id {
123- remove_from_parent_subtasks ( & mut tx , old_parent_id , * subtask_id ) . await ? ;
124- tracing :: debug! (
125- subtask = %subtask_id ,
126- old_parent = %old_parent_id ,
127- "removed subtask from old parent's Subtasks"
128- ) ;
129- }
121+ if let Some ( old_parent_id) = get_task_parent ( & mut tx, * subtask_id) . await ?
122+ && old_parent_id != task_id
123+ {
124+ remove_from_parent_subtasks ( & mut tx , old_parent_id , * subtask_id ) . await ? ;
125+ tracing :: debug! (
126+ subtask = %subtask_id ,
127+ old_parent = %old_parent_id ,
128+ "removed subtask from old parent's Subtasks"
129+ ) ;
130130 }
131131 let _ = set_task_parent ( & mut tx, * subtask_id, Some ( task_id) ) . await ?;
132132 }
0 commit comments