From dfad334780a71db310fc84a5185731f7d7a3554d Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Thu, 3 Jul 2025 15:30:35 +0200 Subject: [PATCH] fix peer add if group not existing --- management/server/store/sql_store.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/management/server/store/sql_store.go b/management/server/store/sql_store.go index 78d6d2ea5..7dbb7860b 100644 --- a/management/server/store/sql_store.go +++ b/management/server/store/sql_store.go @@ -460,17 +460,6 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength, } return s.db.Transaction(func(tx *gorm.DB) error { - for _, g := range groups { - g.StoreGroupPeers() - - if err := tx.Model(&g). - Association("GroupPeers"). - Replace(g.GroupPeers); err != nil { - log.WithContext(ctx).Errorf("failed to save group peers to store: %s", err) - return status.Errorf(status.Internal, "failed to save group peers to store") - } - } - result := tx.Session(&gorm.Session{FullSaveAssociations: true}). Clauses( clause.Locking{Strength: string(lockStrength)}, @@ -485,6 +474,17 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength, return status.Errorf(status.Internal, "failed to save groups to store") } + for _, g := range groups { + g.StoreGroupPeers() + + if err := tx.Model(&g). + Association("GroupPeers"). + Replace(g.GroupPeers); err != nil { + log.WithContext(ctx).Errorf("failed to save group peers to store: %s", err) + return status.Errorf(status.Internal, "failed to save group peers to store") + } + } + return nil }) }