Skip to content

fix(drizzle): return null from deleteOne when the joined select finds no row - #19048

Open
lazerg wants to merge 1 commit into
payloadcms:mainfrom
lazerg:fix/issue-19044-delete-one-missing-row
Open

lazerg wants to merge 1 commit into
payloadcms:mainfrom
lazerg:fix/issue-19044-delete-one-missing-row

Conversation

@lazerg

@lazerg lazerg commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

What?

DELETE /api/payload-preferences/<missing-key> returns a 500 on Postgres instead of a 404.

Why?

When the joined select in deleteOne finds no row, the fallback findFirst reuses the same where, which references the joined user table that the fallback query doesn't join, so Postgres throws missing FROM-clause entry.

How?

Return null right away when the joined select ran and found nothing. The fallback still runs when there are no joins. Added a unit spec for it.

Fixes #19044

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between aebbf75 and 0f68b05.

Files selected for processing: 2
  • packages/drizzle/src/deleteOne.spec.ts
  • packages/drizzle/src/deleteOne.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

deleteOne now returns null when selectDistinct finds no row. A test checks that this path does not call findFirst or deleteWhere.

Changes: deleteOne missing-row handling

Layer / File(s) Summary
Missing-row return and test
packages/drizzle/src/deleteOne.ts, packages/drizzle/src/deleteOne.spec.ts
When the distinct query result has no row with an id, deleteOne returns null before the fallback lookup. The test verifies that findFirst and deleteWhere are not called.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: alessiogr

Merge Risk: Minimal · up to 0f68b

Deleting a missing preference can now return null rather than failing in the fallback lookup. No issue requiring a fix before merge was found.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the change (deleteOne returns null when the joined select finds no row) and the scope (drizzle), which matches the diff: a new early return in packages/drizzle/src/deleteOne.ts plus a …
Description check Passed The description states the symptom (DELETE of a missing key returns 500 on Postgres), the cause (fallback findFirst reuses a where that references the unjoined user table), the fix (return null when t…
Linked Issues check Passed Issue #19044 requires missing-key deletion to avoid the Postgres 500 and return a no-op result such as 404 or 200. In packages/drizzle/src/deleteOne.ts, the code now returns null when `selectDisti…
Out of Scope Changes check Passed The pull request changes only packages/drizzle/src/deleteOne.ts and its focused unit spec. The code change directly addresses issue #19044. The test verifies the affected missing-row behavior. No un…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Title check

Explanation

The title names the change (deleteOne returns null when the joined select finds no row) and the scope (drizzle), which matches the diff: a new early return in packages/drizzle/src/deleteOne.ts plus a unit spec. It is specific and conveys the primary change.

Full details: Description check

Explanation

The description states the symptom (DELETE of a missing key returns 500 on Postgres), the cause (fallback findFirst reuses a where that references the unjoined user table), the fix (return null when the joined select finds nothing), and the added unit spec. It matches the raw summary and the PR objectives.

Full details: Linked Issues check

Explanation

Issue #19044 requires missing-key deletion to avoid the Postgres 500 and return a no-op result such as 404 or 200. In packages/drizzle/src/deleteOne.ts, the code now returns null when selectDistinct returns no row, so it does not execute the fallback query with the joined where. The new deleteOne.spec.ts verifies that the result is null and that neither findFirst nor deleteWhere runs. The existing fallback remains for an absent selectDistinctResult, which preserves the no-join path.

Full details: Out of Scope Changes check

Explanation

The pull request changes only packages/drizzle/src/deleteOne.ts and its focused unit spec. The code change directly addresses issue #19044. The test verifies the affected missing-row behavior. No unrelated implementation or test changes are present in the reviewed diff.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@lazerg

lazerg commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

The tanstack-start E2E failure isn't from this change. That job runs on MongoDB, the same test passes on the next build, and this PR only touches the Drizzle adapter.

@lazerg

lazerg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Hey @jacobsfletch, please take a look when you have time~

This branch has not been deployed

No deployments
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.

DELETE /api/payload-preferences/:key returns 500 when the key does not exist (4.0.0-beta.4, Postgres)

1 participant