From 79a612aa5d95f89cd84148295146a92ccddefa74 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 10 Mar 2026 23:37:29 +0100 Subject: [PATCH] fix: send account deletion notification before deleting user row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When deleting a user via CLI (`vikunja user delete -n`), the user row was deleted first, then `notifications.Notify` was called. But `Notify` calls `User.ShouldNotify()` which queries the database to check the user's status — and since the row was already deleted within the same transaction, it returned `ErrUserDoesNotExist`. Move the notification call before the `DELETE` so the user row still exists when `ShouldNotify` checks it. Closes go-vikunja/vikunja#2335 --- pkg/models/user_delete.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/models/user_delete.go b/pkg/models/user_delete.go index 8ccd137e0..f36a5f2f9 100644 --- a/pkg/models/user_delete.go +++ b/pkg/models/user_delete.go @@ -169,14 +169,17 @@ func DeleteUser(s *xorm.Session, u *user.User) (err error) { } } - _, err = s.Where("id = ?", u.ID).Delete(&user.User{}) + // Notify before deleting the user row, because ShouldNotify will try to + // look up the user and fail if the row is already gone. + err = notifications.Notify(u, &user.AccountDeletedNotification{ + User: u, + }, s) if err != nil { return err } - return notifications.Notify(u, &user.AccountDeletedNotification{ - User: u, - }, s) + _, err = s.Where("id = ?", u.ID).Delete(&user.User{}) + return err } func ensureProjectAdminUser(s *xorm.Session, l *Project) (hadUsers bool, err error) {