Skip to content

fix: findByID returns null for empty ids when disableErrors is true - #18956

Open
Krrishkumar125 wants to merge 1 commit into
payloadcms:mainfrom
Krrishkumar125:fix/find-by-id-disable-errors-invalid-id
Open

Krrishkumar125 wants to merge 1 commit into
payloadcms:mainfrom
Krrishkumar125:fix/find-by-id-disable-errors-invalid-id

Conversation

@Krrishkumar125

Copy link
Copy Markdown

What?

payload.findByID({ id, disableErrors: true }) throws NotFound again when id is null, undefined or ''. It should return null, as it did in 3.90.2 and as the Local API docs describe for disableErrors.

Why?

#18000 (9106bf8) added an explicit isValidID guard before the query. That guard throws before disableErrors is checked, so an invalid id became a hard error even with errors disabled. Calls like findByID({ id: doc.relation, disableErrors: true }) with an unset relation now throw (#18935).

How?

When the id is invalid and disableErrors is set, return null; otherwise throw NotFound as before. Access is still checked first, so an unauthorised caller sees the same result as before.

Added test/collections-rest/findByID-disable-errors.int.spec.ts, which covers null, undefined and '' with and without disableErrors. Without the fix the three disableErrors cases fail. The collections-rest, versions, access-control and collections-graphql int suites pass locally (SQLite adapter). I put the test in its own file because the existing int.spec.ts trips the pre-commit oxlint hook on some unrelated duplicate test titles.

The same guard exists on 3.x; I'm happy to open a backport PR if that's the preferred target for v3 regressions.

Fixes #18935

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: payloadcms/payload/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 29c02095-0507-48e0-a188-f0bf2ea85e4e
📥 Commits

Reviewing files that changed from the base of the PR and between d2ae5e6 and 8fa8c4e.

📒 Files selected for processing: 2
  • packages/payload/src/collections/operations/findByID.ts
  • test/collections-rest/findByID-disable-errors.int.spec.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

findByID now returns null for invalid IDs when disableErrors is enabled. Integration tests cover null, undefined, and empty-string IDs, both with and without the option.

Changes: Invalid ID handling

Layer / File(s) Summary
Invalid ID result and integration coverage
packages/payload/src/collections/operations/findByID.ts, test/collections-rest/findByID-disable-errors.int.spec.ts
When an ID is invalid and disableErrors is enabled, findByID returns null. Integration tests check null, undefined, and empty-string IDs; without the option, they expect a NotFound rejection.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 8fa8c

Invalid IDs can return null when errors are disabled while retaining the default NotFound behavior. No actionable merge blocker is identified.

Architecture risk: 🔵 Low · up to 8fa8c

The change affects 2 systems.

Changed systems: packages/payload, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/payload (library) was modified; 1 changed file maps to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/payload/src/collections/operations/findByID.ts: Added an early disableErrors branch for invalid IDs that returns null instead of reaching the NotFound exception.
  • observed — Modified behavior in test/collections-rest/findByID-disable-errors.int.spec.ts: Adds REST collection findByID tests covering null-like IDs, asserting null resolution with disableErrors: true and NotFound rejection when the option is unset.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: invalid IDs return null when disableErrors is true.
Description check Passed The description directly explains the bug, expected behavior, implementation, tests, regression source, and linked issue.
Linked Issues check Passed Issue #18935 requires findByID to return null for null, undefined, and '' IDs when disableErrors: true, while preserving NotFound without that option. The PR summary reports the invalid-…
Out of Scope Changes check Passed The reported changes are limited to the findByID invalid-ID guard and an integration test for the linked regression. Both changes directly support issue #18935. No unrelated implementation is identi…
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: Linked Issues check

Explanation

Issue #18935 requires findByID to return null for null, undefined, and '' IDs when disableErrors: true, while preserving NotFound without that option. The PR summary reports the invalid-ID guard now returns null when errors are disabled and throws NotFound otherwise. It also reports that access checks remain first. The added integration test covers all three invalid IDs with and without disableErrors.

Full details: Out of Scope Changes check

Explanation

The reported changes are limited to the findByID invalid-ID guard and an integration test for the linked regression. Both changes directly support issue #18935. No unrelated implementation is identified. A possible 3.x backport is explicitly described as separate work and is not included in this assessment.

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

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

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

@Krrishkumar125

Copy link
Copy Markdown
Author

Friendly ping — findByID now returns null for empty/invalid ids when disableErrors is true. Checks are green; happy to revise if you'd rather a different shape.

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.

Regression: findByID with disableErrors: true throws NotFound for null/empty ids since 3.91.0

1 participant