Skip to content

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

Description

@mtolmacs

Describe the Bug

Since 3.91.0, payload.findByID() throws NotFound when the id is null, undefined or "", even with disableErrors: true. In 3.90.2 the same call returned null.

The docs describe disableErrors as "When set to true, errors will not be thrown. Instead, the findByID operation will return null." That no longer holds for invalid ids.

The change came in with #18000 ("check draft read access against the latest version in findByID", 9106bf8). The release notes don't mention it as a behavior change. That commit replaced this guard:

if (!findOneArgs.where?.and?.[0]?.id) {
  throw new NotFound(t)
}

with an explicit id check that runs before the database query:

const isValidID =
  (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && Number.isFinite(id))

if (!isValidID) {
  throw new NotFound(t)
}

The old guard never fired for a null id. where.and[0].id is the { equals: null } object, which is truthy, so the query ran, found nothing, and disableErrors turned that into null. The new guard does fire, and it runs before disableErrors is consulted.

Impact: a common pattern for resolving optional upload fields in server components started throwing after a minor upgrade:

const media = await payload.findByID({
  collection: 'media',
  id: block.backgroundImage, // null when the field is empty
  disableErrors: true,
})

The NotFound propagates as a Server Components render error, so in production every page with an empty upload field returns a 500.

Suggested fix: honor disableErrors in the new guard:

if (!isValidID) {
  if (disableErrors) {
    return null
  }
  throw new NotFound(t)
}

Link to the code that reproduces this issue

https://gist.github.com/mtolmacs/beb3fdc491ee346557a973a6672f1837

Reproduction Steps

  1. Create a blank app with npx create-payload-app@latest and set payload to 3.91.0.
  2. Run this from a server component, route handler or script:
    const payload = await getPayload({ config })
    const result = await payload.findByID({
      collection: 'media',
      id: null as unknown as number,
      disableErrors: true,
    })
    console.log(result)
  3. Expected (and what 3.90.2 does): logs null.
    Actual: throws NotFound: Not Found (status 404).

The same happens with id: undefined and id: ''.

Which area(s) are affected?

area: core

Environment Info

Binaries:
  Node: 24.15.0
  npm: 11.12.1
  Yarn: N/A
  pnpm: 11.24.0
Relevant Packages:
  payload: 3.91.0
  next: 16.3.8
  @payloadcms/db-postgres: 3.91.0
  @payloadcms/db-sqlite: 3.91.0
  @payloadcms/drizzle: 3.91.0
  @payloadcms/email-nodemailer: 3.91.0
  @payloadcms/email-resend: 3.91.0
  @payloadcms/graphql: 3.91.0
  @payloadcms/live-preview: 3.91.0
  @payloadcms/live-preview-react: 3.91.0
  @payloadcms/next/utilities: 3.91.0
  @payloadcms/plugin-cloud-storage: 3.91.0
  @payloadcms/plugin-import-export: 3.91.0
  @payloadcms/plugin-redirects: 3.91.0
  @payloadcms/plugin-seo: 3.91.0
  @payloadcms/richtext-lexical: 3.91.0
  @payloadcms/storage-vercel-blob: 3.91.0
  @payloadcms/translations: 3.91.0
  @payloadcms/ui/shared: 3.91.0
  react: 19.2.4
  react-dom: 19.2.4

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Oct 21, 2026
  2. added
    area: core
    and removed
    validate-reproduction
    on Oct 21, 2026
  3. github-actions commented on Oct 21, 2026

    @github-actions
    Contributor

    Please add a reproduction in order for us to be able to investigate.

    Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

    Why was this issue marked with the invalid-reproduction label?

    To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@latest -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

    To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

    Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

    I added a link, why was it still marked?

    Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

    Useful Resources

  4. changed the title [-]`findByID` with `disableErrors: true` throws `NotFound` for null/empty ids since 3.91.0[/-] [+]Regression: `findByID` with `disableErrors: true` throws `NotFound` for null/empty ids since 3.91.0[/+] on Oct 21, 2026
  5. MilindChatrabhuji commented on Oct 26, 2026

    @MilindChatrabhuji

    I've submitted a fix and unit test coverage in PR #19082 to honor \disableErrors: true\ when !isValidID\ in both \ indByID\ and \ indVersionByID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugarea: coreinvalid-reproductionstatus: needs-triagev3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions