Guard LinkToCommon against overwriting existing catalog link

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é <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-28 20:02:02 +02:00
parent 243c400115
commit 44aca07de3

View File

@@ -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
}