Skip to content

Fix WXR import dropping taxonomies - #1083

Closed
ask-bonk[bot] wants to merge 1 commit into
mainfrom
opencode/issue1061-20260518055858
Closed

ask-bonk[bot] wants to merge 1 commit into
mainfrom
opencode/issue1061-20260518055858

Conversation

@ask-bonk

@ask-bonk ask-bonk Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Diff looks clean. Now post the summary comment for the maintainer.

Summary

Fixed WXR XML import discards taxonomies (issue #1061).

Root cause

The HTTP WXR execute handler (packages/core/src/astro/routes/api/import/wordpress/execute.ts) parsed wp:category, wp:tag, wp:term, and per-item <category domain="…"> blocks but never wrote anything to taxonomies or content_taxonomies. The handleContentCreate() call passed only data, slug, status, etc. — no taxonomy info — so categories/tags/custom taxonomy assignments were silently dropped at the persistence step, exactly as the bug report described.

Fix

  • New helper module packages/core/src/import/wxr-taxonomies.ts with preImportWxrTaxonomies() and attachPostTaxonomies():
    • Pre-pass: find-or-create terms for every wp:category → seeded category taxonomy, every wp:tag → seeded tag taxonomy, and every wp:term → matching custom taxonomy (case-sensitive name match). Idempotent: existing terms are reused, not duplicated. Builds a (taxonomy, slug) → term id lookup.
    • Per-post pass: after each successful handleContentCreate, walk post.categories / post.tags / post.customTaxonomies and call TaxonomyRepository.attachToEntry() for each (which writes the content_taxonomies pivot via the translation_group, matching how seed and admin UI do it).
    • Respects the taxonomy def's collections array (won't tag a products row with a category term linked only to posts).
    • Normalizes WP's post_tag synonym → EmDash tag. Skips nav_menu (handled by importMenusFromWxr).
    • Custom taxonomies without a matching EmDash def are surfaced in a new missingTaxonomies: string[] field on the response (per AGENTS.md backwards-compat rule: additive only). Same for seeded category / tag defs that a user may have deleted.
    • Taxonomy-attach failures don't fail the post import; the content row is already committed, so per-post errors are appended to the existing errors[] array.
  • Wired into execute.ts: pre-pass runs once before the post loop; per-post attach runs after each successful create. New result.taxonomies = { termsCreated, termsReused, assignments, missingTaxonomies } block on the response so the admin UI can report what happened.

Test coverage

New packages/core/tests/unit/import/wxr-taxonomies.test.ts — 14 tests covering:

  • Categories/tags created from wp:category/wp:tag blocks
  • Idempotency (re-running uses existing terms)
  • Per-item-only backfill (terms referenced only by <category nicename> without a top-level block)
  • Custom taxonomies (created when def exists, recorded in missingTaxonomies when not)
  • post_tag synonym normalization
  • nav_menu skip
  • Missing seeded def surfaces in missingTaxonomies
  • Regression for issue WXR XML import parses but discards taxonomies (categories/tags) and post-term assignments #1061 (line 244): pivot rows actually written to content_taxonomies
  • collections filter enforcement (no cross-collection contamination)
  • Pivot uniqueness (re-attach is idempotent via INSERT … ON CONFLICT DO NOTHING)

Verification

  • pnpm --filter emdash test: 3307 tests pass (+1 new for missing-seeded-def case)
  • pnpm --filter emdash typecheck: clean
  • pnpm lint:json: 0 issues in touched files (38 unrelated pre-existing diagnostics elsewhere)
  • pnpm --filter emdash build: clean

Changeset added at .changeset/fix-wxr-taxonomy-import.md (patch bump for emdash).

Closes #1061

github run

@changeset-bot

changeset-bot Bot commented May 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3e4ec97

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator 3e4ec97 May 18 2026, 06:18 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 3e4ec97 May 18 2026, 06:19 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n 3e4ec97 May 18 2026, 06:18 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 3e4ec97 May 18 2026, 06:19 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 18, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 3e4ec97 May 18 2026, 06:19 AM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 860 lines across 4 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@pkg-pr-new

pkg-pr-new Bot commented May 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1083

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1083

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1083

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1083

emdash

npm i https://pkg.pr.new/emdash@1083

create-emdash

npm i https://pkg.pr.new/create-emdash@1083

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1083

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1083

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1083

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1083

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1083

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1083

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1083

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1083

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1083

commit: 3e4ec97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WXR XML import parses but discards taxonomies (categories/tags) and post-term assignments

1 participant