Skip to content

Fix taxonomy assignments across content translations - #2461

Merged
ascorbic merged 3 commits into
mainfrom
fix/shared-taxonomy-assignments
Aug 13, 2026
Merged

ascorbic merged 3 commits into
mainfrom
fix/shared-taxonomy-assignments

Conversation

@ascorbic

@ascorbic ascorbic commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Moves content taxonomy assignments from locale-specific entry IDs to content translation groups, so adding or removing a term through one locale is reflected by every sibling translation. A forward-only migration preserves existing assignments, safely collapses duplicate locale rows, and replaces obsolete denormalized pivot indexes with a group lookup index. Reads, writes, imports, seeds, counts, and taxonomy-filtered loading now resolve through the content translation group while continuing to return the term variant for the requested locale.

Closes #1348

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (not applicable: no admin UI strings changed). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: not applicable; this is a bug fix.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: GPT-5 Codex

Screenshots / test output

No visual changes.

Validation:

  • pnpm format
  • pnpm lint:quick
  • pnpm lint
  • pnpm typecheck
  • pnpm --silent lint:json | jq '.diagnostics | length' → 0
  • Targeted Vitest regression suite: 12 files, 120 tests passed
  • pnpm --filter emdash build
  • pnpm query-counts --update
  • pnpm query-counts --skip-build --skip-seed (query counts and query text match)
  • git diff --check

The dialect-aware tests ran against SQLite locally. EMDASH_TEST_PG was not configured, so PostgreSQL will be exercised by CI.

Copilot AI lite review requested due to automatic review settings August 13, 2026 15:26
@changeset-bot

changeset-bot Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3c3dd7

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

This PR includes changesets to release 17 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/plugin-mcp-smoke Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-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 Aug 13, 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 b3c3dd7 Aug 13 2026, 04:27 PM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 829 lines across 24 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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 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 b3c3dd7 Aug 13 2026, 04:27 PM

@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 13, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 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 failed
View logs
emdash-demo-do b3c3dd7 Aug 13 2026, 04:28 PM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes taxonomy drift across translated content by changing content_taxonomies to key assignments by the content translation_group (instead of per-locale content row IDs), so term add/remove operations are shared across sibling translations while term resolution still returns the locale-appropriate term variant.

Changes:

  • Introduces migration 066_content_taxonomy_entry_groups to forward-migrate existing pivot rows to group-keyed entry_id, dedupe sibling-locale rows, drop legacy denorm indexes, and add a group lookup index.
  • Updates taxonomy reads/writes, loader taxonomy-filtered listings, counts, imports, and seeding paths to resolve through the content translation_group.
  • Adjusts and adds regression tests (including migration coverage) and updates query-count snapshots + changeset.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
scripts/query-counts.queries.sqlite.json Updates recorded SQL shapes to join taxonomy pivots by content translation_group.
packages/core/tests/unit/loader-taxonomy-pivot.test.ts Updates pivot-listing assertions to rely on authoritative content rows (not denorm pivot fields).
packages/core/tests/unit/import/wxr-taxonomies.test.ts Ensures seeded/imported content rows include translation_group for new pivot semantics.
packages/core/tests/unit/i18n/repair-locale-casing.test.ts Updates locale casing repair coverage to reflect group-keyed taxonomy assignments.
packages/core/tests/integration/wordpress-import/wxr-i18n-taxonomies.test.ts Updates WPML import expectations to shared-group assignment behavior.
packages/core/tests/integration/taxonomies/taxonomy-translation-group-assignments.test.ts New integration test validating cross-locale assignment propagation with locale-correct term resolution.
packages/core/tests/integration/taxonomies/taxonomy-locale-terms.test.ts Updates locale-term resolution test for group-keyed content_taxonomies entry IDs.
packages/core/tests/integration/loader-taxonomy-pivot-plan.test.ts Updates EXPLAIN plan assertions for the new group-lookup pivot/index strategy.
packages/core/tests/integration/database/migrations.test.ts Registers the new migration in integration migration coverage.
packages/core/tests/integration/database/content-taxonomy-entry-groups-migration.test.ts New integration test for migration correctness + deduping behavior.
packages/core/src/taxonomies/term-counts.ts Counts published/visible assignments by joining content rows on translation_group.
packages/core/src/taxonomies/index.ts Updates term resolution helpers to fetch terms via group-keyed pivot and locale-scoped term rows.
packages/core/src/seed/apply.ts Uses repository helpers to clear/apply taxonomy assignments under new semantics.
packages/core/src/loader.ts Updates hydration + taxonomy-filtered listing query builder to join via translation_group and rely on ec_* rows for predicates.
packages/core/src/import/wxr-taxonomies.ts Updates WXR import attachment/replacement logic to operate on shared content groups.
packages/core/src/i18n/repair-locale-casing.ts Removes pivot-locale rewrites now that taxonomy assignments are locale-agnostic on the content side.
packages/core/src/database/types.ts Documents content_taxonomies.entry_id as content translation_group and marks denorm columns as legacy/nullable.
packages/core/src/database/repositories/taxonomy.ts Reworks attach/detach/get/set/clear to normalize both sides to translation_groups and adds entry group resolution.
packages/core/src/database/repositories/content.ts Removes pivot re-stamping logic tied to legacy denormalized pivot columns.
packages/core/src/database/migrations/runner.ts Registers migration 066 in the static migration map.
packages/core/src/database/migrations/066_content_taxonomy_entry_groups.ts New forward-only migration implementing the pivot entry_id migration + index changes.
packages/core/src/astro/routes/api/import/wordpress/execute.ts Updates importer semantics commentary to reflect group-keyed taxonomy assignments.
packages/core/src/api/handlers/content.ts Removes translation-time taxonomy copy since assignments are now shared by content group.
.changeset/shared-taxonomy-assignments.md Adds a patch changeset describing the user-visible behavior fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change moves taxonomy assignments from per-locale content row IDs to shared content translation groups, which is the right model for the bug described in #1348 and is implemented consistently across the migration, repositories, loader, import, seed, and count paths. The forward-only migration correctly collapses duplicate per-locale rows and preserves existing assignments, and the read/write paths now resolve terms per locale while sharing the assignment on the group.

I found one real regression in the visible term-count query and one stale comment:

  • packages/core/src/taxonomies/term-counts.ts now joins content_taxonomies to ec_* on e.translation_group = ct.entry_id. Because ct.entry_id now stores the content translation group, and because a content group has one row per locale, the CROSS JOIN produces one result row for every locale variant of the content group. COUNT(*) therefore multiplies term usage counts by the number of sibling translations. The existing translation-aware test passes only because it attaches a single term group; with two different term groups attached to a translated entry, each count would be inflated. The fix is to count distinct content groups.
  • packages/core/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts still documents the old storage model (“Terms are stored against the per-locale entry row”), which is no longer true and is misleading for future maintainers.

Other cross-cutting concerns look fine: SQL is parameterized and identifiers are validated; locale filtering is preserved on the joined ec_* row and on term resolution; the new index replaces the now-unused denorm indexes; no new logged-out queries are introduced; and the changeset is user-facing and appropriate.


Findings

  • [needs fixing] packages/core/src/taxonomies/term-counts.ts:50

    The CROSS JOIN now matches each pivot row against every locale row that shares the content translation group (e.translation_group = ct.entry_id). Because ct.entry_id stores the group after this PR, a translated entry with n locale rows produces n joined rows per pivot row, so COUNT(*) inflates visible term usage counts by the number of sibling translations. A content group tagged with two different terms would report 2 uses per term instead of 1.

    Use a distinct count of content groups so each logical entry is counted once:

    		SELECT ct.taxonomy_id AS taxonomy_id, COUNT(DISTINCT ct.entry_id) AS count
    

    A regression test that attaches two distinct term groups to a translated entry and asserts 1 for each term count would catch this.

  • [suggestion] packages/core/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts:37

    This comment describes the old storage model. After migration 066, assignments are stored against the content translation group, not the per-locale entry row. Update the comment to avoid misleading future readers:

    		// Terms are stored against the content translation_group, so one
    		// assignment spans every locale. Resolve the entry's own locale
    		// server-side (deterministic, not client-spoofable) so only the matching
    		// term variant is returned — see issue #1218.
    

@ascorbic
ascorbic force-pushed the fix/shared-taxonomy-assignments branch from 43ba79c to 0f5002d Compare August 13, 2026 16:12
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed needs-rebase review/needs-review No maintainer or bot review yet labels Aug 13, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2461

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2461

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2461

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2461

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2461

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2461

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2461

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: b3c3dd7

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 13, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of #2461. The two issues from the previous review are both resolved in this revision:

  1. packages/core/src/taxonomies/term-counts.ts now counts distinct content translation groups (COUNT(DISTINCT e.translation_group)) so a translated entry with multiple sibling locales and more than one assigned term group does not inflate visible term counts. The updated regression test attaches two different term groups to a translated entry and asserts each count is 1, which directly exercises the bug.

  2. The stale comment in packages/core/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts has been updated to describe the new group-based storage model.

I also re-checked the rest of the diff for systemic gaps:

  • The migration (068) correctly collapses duplicate per-locale pivot rows into one group-level assignment and preserves existing assignments with ON CONFLICT DO NOTHING. The delete target (id != translation_group) removes only the obsolete locale-variant rows.
  • All read/write/import/seed/count paths now resolve content_taxonomies.entry_id through resolveEntryTranslationGroup, and the loader, taxonomy repository, term-counts, and taxonomies index queries all join/filter on the content translation group while preserving locale filtering on the joined ec_* row and on term resolution.
  • The byline filter in the pivot query was correctly tightened to cb.content_id = r.id (locale-specific row), since byline credits remain per-locale.
  • The legacy denormalized pivot columns and their indexes are no longer used or referenced; the new idx_content_taxonomies_group_lookup index replaces them.
  • No remaining code references the old denormalized pivot columns (ct.status, ct.locale, ct.published_at, etc.).
  • SQL is parameterized and identifiers are validated. No new logged-out route round-trips are introduced (the taxonomy listing is still a single join query).

I could not independently inspect the full query-count snapshot diff because that hunk was elided from the provided diff, but the author reports the snapshots were regenerated and match, and there are no obvious sources of an additional round-trip in the changes.

No blocking issues remain; this is a clean fix for the shared-assignment model.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 13, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Aug 13, 2026
@ascorbic
ascorbic merged commit 598e6fb into main Aug 13, 2026
49 of 50 checks passed
@ascorbic
ascorbic deleted the fix/shared-taxonomy-assignments branch August 13, 2026 17:20
@emdashbot emdashbot Bot mentioned this pull request Aug 13, 2026
khoinguyenpham04 pushed a commit that referenced this pull request Aug 14, 2026
…ublish (#2466)

* fix(core): remove stale restampEntryPivot call that crashes content publish

The merge of #2460 and #2461 left main with a publish path that calls
restampEntryPivot, a method #2461 deleted together with the pivot
denormalization it maintained. Every content publish now throws
"this.restampEntryPivot is not a function".

No replacement call is needed: since migration 068 the pivot columns the
call re-stamped are legacy, and reads join the authoritative ec_* row.

* chore: add changeset for the publish crash fix

The fix changes the published emdash package, and release notes are
built from changeset files, so the crash fix needs an entry even though
the crash itself never shipped in a release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core review/approved Approved; no new commits since size/XL

Projects

None yet

2 participants