Skip to content

Commit 892b266

Browse files
committed
refactor(address-service): DOMA-12746 add self-link check before updating possibleDuplicateOf in upsertHeuristics
Add validation to prevent setting possibleDuplicateOf to the same address (self-link). Log warning when rootAddressId equals addressId and skip the update operation to avoid creating invalid duplicate relationships.
1 parent d2161f5 commit 892b266

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

apps/address-service/domains/common/utils/services/search/heuristicMatcher.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,17 @@ async function upsertHeuristics (context, addressId, heuristics, providerName, d
290290

291291
if (bestOverallConflict) {
292292
const rootAddressId = await findRootAddress(bestOverallConflict.existingAddressId)
293-
await AddressServerUtils.update(context, addressId, {
294-
...dvSender,
295-
possibleDuplicateOf: { connect: { id: rootAddressId } },
296-
})
293+
if (rootAddressId === addressId) {
294+
logger.warn({
295+
msg: 'Skip possibleDuplicateOf self-link',
296+
data: { addressId, rootAddressId, bestOverallConflict },
297+
})
298+
} else {
299+
await AddressServerUtils.update(context, addressId, {
300+
...dvSender,
301+
possibleDuplicateOf: { connect: { id: rootAddressId } },
302+
})
303+
}
297304
}
298305
}
299306

0 commit comments

Comments
 (0)