From fd77e041a1ad96b17142690a5dba9ec3a62e244c Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 24 Feb 2026 11:43:55 +0100 Subject: [PATCH] fix: add transaction begin to db.NewSession() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All sessions now start with an active transaction. This makes multi-statement write operations atomic — if any step fails, all changes are rolled back instead of leaving the database in an inconsistent state. Callers must call s.Commit() for writes to persist. s.Close() auto-rollbacks uncommitted transactions. --- pkg/db/db.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/db/db.go b/pkg/db/db.go index 1d8f331fa..13ee7e6ed 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -403,9 +403,13 @@ func WipeEverything() error { return nil } -// NewSession creates a new xorm session +// NewSession creates a new xorm session with an active transaction. +// The caller must call s.Commit() on success or s.Rollback() on error. +// s.Close() will auto-rollback any uncommitted transaction. func NewSession() *xorm.Session { - return x.NewSession() + s := x.NewSession() + _ = s.Begin() + return s } // Type returns the db type of the currently configured db