Skip to content

fix(core): remove byline credits when content is permanently deleted - #3158

Merged
ascorbic merged 3 commits into
emdash-cms:mainfrom
danielmlr:fix/permanent-delete-byline-credits
Sep 22, 2026
Merged

ascorbic merged 3 commits into
emdash-cms:mainfrom
danielmlr:fix/permanent-delete-byline-credits

Conversation

@danielmlr

Copy link
Copy Markdown
Member

What does this PR do?

Removes an entry's byline credits when the entry is permanently deleted.

Credits are stored per entry row with no foreign key, and permanent delete never removed them, so they outlived the entry. The handler now deletes the purged row's credits alongside the SEO, comment and revision cleanup. Each translation has its own credit rows, so unlike the term assignments in #3091 no check for remaining translations is needed, and the other translations keep their credits.

Every reader looks credits up from an entry that still exists, so nothing shows the leftovers today, with one exception. Seeding creates a slugless entry in a non-routable collection under its seed ID and writes no credits for an entry without any, so re-applying a seed after a purge gave the re-created entry the old credits. Credits that earlier deletes left behind stay, and seed apply is unchanged.

Part of #1683, where the byline leftover was raised.

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) (the full emdash suite)
  • 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 (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main. (n/a: no admin UI change)
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/... (n/a: bug fix)
  • I have included screenshots below if this PR changes the UI (n/a: no UI change)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5

Screenshots / test output

Not applicable for screenshots. Against the unmodified handler, all four cases in permanent-delete-bylines.test.ts fail on SQLite and PostgreSQL:

 × handleContentPermanentDelete: byline credits [sqlite] > removes the credits of the purged entry
 × handleContentPermanentDelete: byline credits [sqlite] > keeps the credits of another translation
 × handleContentPermanentDelete: byline credits [sqlite] > keeps the credits of an entry with the same id in another collection
 × handleContentPermanentDelete: byline credits [sqlite] > does not credit a seed entry re-created under the purged entry's id
AssertionError: expected [ Array(1) ] to deeply equal []

With the change, all four pass on SQLite and PostgreSQL, and the full emdash suite passes on SQLite:

 Test Files  563 passed | 2 skipped (565)
      Tests  6885 passed | 10 skipped (6895)

Byline credits are stored per entry row in `_emdash_content_bylines`, with
no foreign key to the content table. Permanently deleting an entry removes
its row, SEO data, comments and revisions, but not its credits.

Against the current handler, a purged entry's credit rows stay behind, on
SQLite and PostgreSQL. Two cases pin what the purge must leave alone:
another translation's credits, and the credits of an entry with the same
id in another collection. A fourth shows where the leftovers surface: a
seed that re-creates a slugless entry under its seed ID, with no credits
of its own, comes back with the purged entry's credits.
Credits belong to a single entry row: saving an entry writes rows for its
own id, and a new translation gets copies under its own id. Permanent
delete never removed them, so they outlived the entry.

The handler now deletes the purged row's credits next to the SEO, comment
and revision cleanup. Unlike term assignments, no check for surviving
translations applies, since no other row reads these credits. Credits left
behind by earlier deletes stay.
@changeset-bot

changeset-bot Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3230f09

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

This PR includes changesets to release 12 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 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

@pkg-pr-new

pkg-pr-new Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-test

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-test@3158

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-loader

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-loader@3158

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-moderation@3158

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 3230f09

@danielmlr
danielmlr marked this pull request as ready for review September 19, 2026 16:08
@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Sep 19, 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.

This is the right fix for the reported orphan-credit problem, implemented in the right place. Permanent delete already cleans up SEO, comments, and revisions; byline credits are another per-entry dependent row and belong in the same transaction. By deleting them inside handleContentPermanentDelete before commit, the seed re-apply case described in #1683 is fixed going forward without changing seed behavior.

I checked:

  • The handler change is inside the existing transaction and only runs when the row was actually deleted.
  • BylineRepository.deleteContentBylines uses the existing junction index (idx_content_bylines_content) and follows the same safe, parameterized Kysely patterns as sibling deleteByContent / deleteByEntry methods.
  • The per-entry cleanup is correctly not shared across translations or across collections, consistent with the column-key design of _emdash_content_bylines.
  • The regression test covers the bug, translation isolation, collection isolation, and the seed re-apply scenario on both SQLite and PostgreSQL.
  • The changeset is accurate and user-facing.

No blockers or convention violations. The PR is clean.

@emdashbot emdashbot Bot added review/approved Approved; no new commits since and removed review/needs-review No maintainer or bot review yet labels Sep 19, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@ascorbic
ascorbic merged commit 1fea699 into emdash-cms:main Sep 22, 2026
59 checks passed
@danielmlr
danielmlr deleted the fix/permanent-delete-byline-credits branch September 22, 2026 11:34
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/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants