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:
@@ -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++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user