[GH-ISSUE #2329] bug: new task gets wrong position in views other than the one it was created in #6641

Closed
opened 2026-04-20 17:14:09 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @maggch97 on GitHub (Mar 2, 2026).
Original GitHub issue: https://github.com/go-vikunja/vikunja/issues/2329

Description

When creating a task in a project that has multiple views (e.g. two list views), the new task gets the correct position (top of the list) only in the view where it was created. In all other views, it appears in the middle of the list with an incorrect position value.

Root Cause

In calculateNewPositionForTask (pkg/models/task_position.go:330), the calculated position is written back to the shared *Task struct:

t.Position = lowestPosition.Position / 2

This function is called in a loop over all views in setTaskInBucketInViews (pkg/models/tasks.go), sharing the same *Task pointer. After the first view sets t.Position, subsequent views see t.Position != 0 and skip the position calculation entirely, reusing the value from the first view.

Steps to Reproduce

  1. Create a project with two list views (View A and View B)
  2. Open View A, which has tasks with positions in a certain range
  3. Create a new task in View A
  4. Switch to View B — the new task appears in the middle instead of at the top

Expected Behavior

The new task should appear at the top of every view, with each view independently calculating the position based on its own lowest position.

Fix

Use a local variable instead of modifying t.Position:

position := lowestPosition.Position / 2
// ...
Position: calculateDefaultPosition(t.Index, position),

Introduced in commit 429c7ca2c (feat(task): always insert new tasks at the top).

Originally created by @maggch97 on GitHub (Mar 2, 2026). Original GitHub issue: https://github.com/go-vikunja/vikunja/issues/2329 ## Description When creating a task in a project that has multiple views (e.g. two list views), the new task gets the correct position (top of the list) only in the view where it was created. In all other views, it appears in the middle of the list with an incorrect position value. ## Root Cause In `calculateNewPositionForTask` (pkg/models/task_position.go:330), the calculated position is written back to the shared `*Task` struct: ```go t.Position = lowestPosition.Position / 2 ``` This function is called in a loop over all views in `setTaskInBucketInViews` (pkg/models/tasks.go), sharing the same `*Task` pointer. After the first view sets `t.Position`, subsequent views see `t.Position != 0` and skip the position calculation entirely, reusing the value from the first view. ## Steps to Reproduce 1. Create a project with two list views (View A and View B) 2. Open View A, which has tasks with positions in a certain range 3. Create a new task in View A 4. Switch to View B — the new task appears in the middle instead of at the top ## Expected Behavior The new task should appear at the top of every view, with each view independently calculating the position based on its own lowest position. ## Fix Use a local variable instead of modifying `t.Position`: ```go position := lowestPosition.Position / 2 // ... Position: calculateDefaultPosition(t.Index, position), ``` Introduced in commit 429c7ca2c (`feat(task): always insert new tasks at the top`).
Author
Owner

@maggch97 commented on GitHub (Mar 2, 2026):

Fix is included in https://github.com/go-vikunja/vikunja/pull/2320 (commit 3f4bdf2a2).

<!-- gh-comment-id:3981721031 --> @maggch97 commented on GitHub (Mar 2, 2026): Fix is included in https://github.com/go-vikunja/vikunja/pull/2320 (commit 3f4bdf2a2).
Author
Owner

@vikunja-bot-app[bot] commented on GitHub (Mar 2, 2026):

This issue has been fixed in #2320, please check with the next unstable build (should be ready for deployment in ~30min, also on the demo).

<!-- gh-comment-id:3982830726 --> @vikunja-bot-app[bot] commented on GitHub (Mar 2, 2026): This issue has been fixed in #2320, please check with the next unstable build (should be ready for deployment in ~30min, also on [the demo](https://try.vikunja.io)).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#6641