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, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
} }
if err := newPattern.Insert(ctx, tx, scope); err != nil { wasInserted, err := newPattern.InsertIfNotExists(ctx, tx, scope)
if errors.Is(err, coredata.ErrResourceAlreadyExists) { if err != nil {
continue
}
return fmt.Errorf("cannot insert cookie pattern: %w", err) return fmt.Errorf("cannot insert cookie pattern: %w", err)
} }
if !wasInserted {
continue
}
patternID = newPattern.ID patternID = newPattern.ID
inserted++ inserted++
} }