Fix aborted transaction on duplicate cookie pattern insert

Use InsertIfNotExists instead of Insert with error check, since
a unique-violation aborts the PostgreSQL transaction even when caught.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-30 11:14:03 +04:00
parent 427bbbaf5c
commit 6482361352

View File

@@ -2640,12 +2640,13 @@ func (s *Service) ReportDetectedCookies(
CreatedAt: now,
UpdatedAt: now,
}
if err := newPattern.Insert(ctx, tx, scope); err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) {
continue
}
wasInserted, err := newPattern.InsertIfNotExists(ctx, tx, scope)
if err != nil {
return fmt.Errorf("cannot insert cookie pattern: %w", err)
}
if !wasInserted {
continue
}
patternID = newPattern.ID
inserted++
}