Skip to content

PROD-1320 - Fix bug for duplicate items when using overwrite flag #135

Merged
5PK merged 2 commits into
mainfrom
PROD-1320
May 21, 2026
Merged

PROD-1320 - Fix bug for duplicate items when using overwrite flag #135
5PK merged 2 commits into
mainfrom
PROD-1320

Conversation

@jules-exel
Copy link
Copy Markdown
Contributor

@jules-exel jules-exel commented May 20, 2026

Summary

Fixes a duplicate-content bug that fires when --overwrite is used and the mapped target content item has been deleted in the target CMS. The previous code path silently created a new item (and a new mapping row), accumulating duplicates over repeated syncs. This change makes overwrite reuse the mapped targetContentID so the API attempts an update against the deleted ID rather than falling through to a create.

Changes

src/lib/pushers/content-pusher/util/change-detection.ts

  • In the conflict branch (both source and target versions newer than mapped), state.overwrite === true now returns shouldUpdate: true instead of flagging an unresolvable conflict.

src/lib/pushers/content-pusher/content-batch-processor.ts

  • In prepareContentPayloads, when a mapping exists but the local target file is missing (isTargetContentItemDeleted) and state.overwrite is on, the payload reuses existingMapping.targetContentID instead of -1. Without overwrite, falls back to the prior behavior.
  • The cross-locale fallback (findContentInOtherLocale) is now only invoked when there is no mapping AND no target entity — previously it could overwrite a just-resolved existingContentID.

.gitignore

  • Adds .claude/settings.local.json so local Claude Code settings stay untracked.

Test plan

  • Manual: with --overwrite, delete a target item in the target CMS, run sync, confirm a duplicate is NOT created (the API either updates the existing item or surfaces a clear failure).
  • Manual: without --overwrite, confirm prior conflict-handling behavior is unchanged (both source and target newer → reports conflict).
  • Manual: cross-locale fallback still resolves when a content item exists in another locale's mapping but not this one.
  • npm run build passes (verified locally).

jules-exel and others added 2 commits May 20, 2026 11:11
When --overwrite is set and the local mapping references a target content
item that no longer exists on disk, send the payload with the mapped
targetContentID rather than -1, so we attempt to update the deleted item
rather than silently creating a duplicate. Also extend the conflict
branch in change-detection so overwrite resolves to shouldUpdate instead
of flagging an unresolvable conflict.

Additional housekeeping:
- guard the cross-locale fallback so it only fires when no mapping exists
  at all (was previously overriding existingContentID even when set)
- add .claude/settings.local.json to .gitignore
- prettier pass on content-batch-processor.ts and change-detection.ts

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jules-exel jules-exel changed the title fix: reuse stale target ID when overwriting deleted content (PROD-1320) PROD-1320 - Fix bug for duplicate items when using overwrite flag May 20, 2026
@5PK 5PK merged commit 014c5d2 into main May 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants