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