From 44aca07de350e653d1a466ea4cd474eb48cd90b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Thu, 28 May 2026 20:02:02 +0200 Subject: [PATCH] Guard LinkToCommon against overwriting existing catalog link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an org third party already has a common_third_party_id set, LinkToCommon now skips the write instead of overwriting it with a different catalog ID. This prevents heuristic or agent false positives from corrupting a previous, more accurate association. Signed-off-by: Émile Ré --- pkg/thirdparty/match.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/thirdparty/match.go b/pkg/thirdparty/match.go index c7608ad1d..ef859d9f2 100644 --- a/pkg/thirdparty/match.go +++ b/pkg/thirdparty/match.go @@ -194,8 +194,9 @@ func stripCorporateSuffixes(lowerName string) string { // LinkToCommon writes common_third_party_id onto an org ThirdParty so // future matches against the same CommonThirdParty can short-circuit // to the exact-link path in O(1). No-op when the field is already set -// to commonID; otherwise writes the field via ThirdParty.Update and -// updates the receiver in place. +// (to any value) — we never overwrite an existing catalog link because +// a heuristic or agent false-positive must not corrupt a previous, +// possibly more accurate, association. func LinkToCommon( ctx context.Context, tx pg.Tx, @@ -203,7 +204,7 @@ func LinkToCommon( orgThirdParty *coredata.ThirdParty, commonID gid.GID, ) error { - if orgThirdParty.CommonThirdPartyID != nil && *orgThirdParty.CommonThirdPartyID == commonID { + if orgThirdParty.CommonThirdPartyID != nil { return nil }