Skip to content

Fix duplicate posts when re-importing content without slugs - #8138

Draft
faisalahammad wants to merge 2 commits into
Automattic:trunkfrom
faisalahammad:fix/8066-import-dedup-by-source-id
Draft

Fix duplicate posts when re-importing content without slugs#8138
faisalahammad wants to merge 2 commits into
Automattic:trunkfrom
faisalahammad:fix/8066-import-dedup-by-source-id

Conversation

@faisalahammad

Copy link
Copy Markdown

Resolves #8066

Proposed Changes

Content import duplicates posts when a source CSV row has no slug. The import only matched existing posts by slug, so a row with an empty slug was always treated as new and inserted again on re-import. One reported run of 1,320 lesson rows produced 1,342 lesson posts.

The fix persists the source id as a private post meta (_sensei_import_id) on every imported post. When the slug lookup misses, the import now falls back to that meta to find the existing post, so re-importing the same CSV updates the same posts instead of creating new ones. Rows with no slug and no id still cannot be matched and are documented as a known limit.

Screenshots

No visual change.

Testing Instructions

  • Import a CSV that contains a row with an empty slug and a non-empty id.
  • Import the same CSV a second time.
  • Confirm the post count does not double: the slug-less rows resolve to their existing posts.

New/Updated Hooks

None.

Deprecated Code

None.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch - Backward-compatible bug fixes

Type

  • Fixed - Fixes a bug

Message

Fix duplicate posts when re-importing content with empty slug columns by persisting the source import id on each imported post.

@faisalahammad

faisalahammad commented Aug 16, 2026

Copy link
Copy Markdown
Author

CI status update

Psalm (8.2) fixed. The import-id refactor in class-sensei-import-model.php surfaced five static-analysis issues (all false positives on unit-tested, runtime-correct code), baselined in config/psalm/psalm-baseline.xml rather than worked around (./vendor/bin/psalm now exits clean).

Two checks remain, unfixable here:

  • Check Milestone — PR has no milestone; I lack push access to Automattic/sensei, so a maintainer must assign one.
  • Expose Built ArtifactHTTP 403 uploading to the ci-playground-artifacts release. Fork PRs get read-only GITHUB_TOKEN, so release asset upload is denied; only passes for org-repo branches.

@faisalahammad
faisalahammad force-pushed the fix/8066-import-dedup-by-source-id branch from bc6f6d6 to fa684a4 Compare August 16, 2026 16:26
Imported posts now store the source import id as private post meta.
When a slug is empty, the import looks up that meta to find the
existing post instead of creating a new one. This stops re-importing
the same CSV from duplicating draft rows that have no slug.
@faisalahammad
faisalahammad force-pushed the fix/8066-import-dedup-by-source-id branch from fa684a4 to 192ac43 Compare August 16, 2026 16:33
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.

Content import creates duplicate posts for slug-less rows (drafts) on re-import or batch replay

1 participant