Repository navigation
Fix taxonomy assignments across content translations - #2461
Conversation
🦋 Changeset detectedLatest commit: b3c3dd7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | b3c3dd7 | Aug 13 2026, 04:27 PM |
Scope checkThis 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. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | b3c3dd7 | Aug 13 2026, 04:27 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
emdash-demo-do | b3c3dd7 | Aug 13 2026, 04:28 PM |
There was a problem hiding this comment.
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_groupsto forward-migrate existing pivot rows to group-keyedentry_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.
There was a problem hiding this comment.
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.tsnow joinscontent_taxonomiestoec_*one.translation_group = ct.entry_id. Becausect.entry_idnow stores the content translation group, and because a content group has one row per locale, theCROSS JOINproduces 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].tsstill 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:50The
CROSS JOINnow matches each pivot row against every locale row that shares the content translation group (e.translation_group = ct.entry_id). Becausect.entry_idstores the group after this PR, a translated entry with n locale rows produces n joined rows per pivot row, soCOUNT(*)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 countA regression test that attaches two distinct term groups to a translated entry and asserts
1for each term count would catch this. -
[suggestion]
packages/core/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts:37This 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.
43ba79c to
0f5002d
Compare
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
Re-review of #2461. The two issues from the previous review are both resolved in this revision:
-
packages/core/src/taxonomies/term-counts.tsnow 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 is1, which directly exercises the bug. -
The stale comment in
packages/core/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].tshas 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_idthroughresolveEntryTranslationGroup, 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 joinedec_*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_lookupindex 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.
…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.
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
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
No visual changes.
Validation:
pnpm formatpnpm lint:quickpnpm lintpnpm typecheckpnpm --silent lint:json | jq '.diagnostics | length'→0pnpm --filter emdash buildpnpm query-counts --updatepnpm query-counts --skip-build --skip-seed(query counts and query text match)git diff --checkThe dialect-aware tests ran against SQLite locally.
EMDASH_TEST_PGwas not configured, so PostgreSQL will be exercised by CI.