From 6482361352d0b4261804d64b67dea7189e36bff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Thu, 30 Apr 2026 11:14:03 +0400 Subject: [PATCH] Fix aborted transaction on duplicate cookie pattern insert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use InsertIfNotExists instead of Insert with error check, since a unique-violation aborts the PostgreSQL transaction even when caught. Signed-off-by: Émile Ré --- pkg/cookiebanner/service.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index ac38d25db..b40f69622 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -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++ }