payloadcms/payload · warning · NotFound
Not Found
Error message
Not Found
What it means
In `findByIDOperation`, before the DB query it checks `findOneArgs.where?.and?.[0]?.id`; if absent it throws `NotFound(t)`. The combined where is `combineQueries({ id: { equals: id } }, accessResult)` whose first `and` entry is the id clause — so a missing/falsy `id` means the lookup has no id target.
Source
Thrown at packages/payload/src/collections/operations/findByID.ts:189
getSelectMode(select) === 'include'
) {
dbSelect = { ...select, createdAt: true, updatedAt: true }
}
const findOneArgs: FindOneArgs = {
collection: collectionConfig.slug,
draftsEnabled: replaceWithVersion,
joins: req.payloadAPI === 'GraphQL' ? false : sanitizedJoins,
locale: locale!,
req: {
transactionID: req.transactionID,
} as PayloadRequest,
select: dbSelect,
where: fullWhere,
}
if (!findOneArgs.where?.and?.[0]?.id) {
throw new NotFound(t)
}
const docWithLocales = await req.payload.db.findOne(findOneArgs)
if (!docWithLocales && !args.data) {
if (!disableErrors) {
throw new NotFound(req.t)
}
return null!
}
let result: DataFromCollectionSlug<TSlug> =
(args.data as DataFromCollectionSlug<TSlug>) ?? docWithLocales!
// /////////////////////////////////////
// Add collection property for auth collections
// /////////////////////////////////////
View on GitHub (pinned to 00c58b35c0)
Solutions
- Ensure a non-empty `id` is passed.
- Validate the route param before calling `findByID`.
Example fix
// before
await payload.findByID({ collection: 'posts', id: maybeId })
// after
if (!id) throw new Error('id required')
await payload.findByID({ collection: 'posts', id }) Defensive patterns
Strategy: validation
Validate before calling
function requireId(id) {
if (id === undefined || id === null || id === '') {
throw new Error('id is required')
}
} Type guard
function hasId(id): id is string | number {
return id !== undefined && id !== null && id !== ''
} Prevention
- Always validate id presence before `findByID`.
- Avoid calling `findByID` with optional/undefined ids.
When it happens
Trigger: Calling `findByID({ collection, id })` (or `GET /api/{collection}/{id}`) with `id` undefined, null, or empty string, so the combined where clause's first `and` element lacks an `id`.
Common situations: A route param missing (`/api/posts/` with no id); an `id` variable undefined due to a typo; a programmatic call with `id: undefined`.
Related errors
- Missing ID of version.
- Invalid template given
- Invalid database type given. Valid types are: ${Object.value
- No version or tag "${version}" found for package: ${packageN
- Either collection or globalSlug must be passed.
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/5d8d77c9d57de0ba.
Report an issue: GitHub.