payloadcms/payload · error · NotFound

Not Found

Error message

Not Found

What it means

Thrown by restoreVersionOperation when the underlying payload.db.findGlobalVersions query for the requested id returns zero docs. The version to restore does not exist in the versions table. Surfaced as NotFound (HTTP 404).

Source

Thrown at packages/payload/src/globals/operations/restoreVersion.ts:72

    // /////////////////////////////////////

    if (!overrideAccess) {
      await executeAccess({ slug: globalConfig.slug, req }, globalConfig.access.update)
    }

    // /////////////////////////////////////
    // Retrieve original raw version
    // /////////////////////////////////////

    const { docs: versionDocs } = await payload.db.findGlobalVersions<any>({
      global: globalConfig.slug,
      limit: 1,
      req,
      where: { id: { equals: id } },
    })

    if (!versionDocs || versionDocs.length === 0) {
      throw new NotFound(req.t)
    }

    const rawVersion = versionDocs[0]!

    // Patch globalType onto version doc
    rawVersion.version.globalType = globalConfig.slug

    // Overwrite draft status if draft is true

    if (draft) {
      rawVersion.version._status = 'draft'
    }
    // /////////////////////////////////////
    // fetch previousDoc
    // /////////////////////////////////////

    const previousDoc = await payload.findGlobal({
      slug: globalConfig.slug,

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Verify the version exists via findGlobalVersions({ where: { id: { equals } } }) before restoring.
  2. In UI flows, disable the restore button once the version is gone and refresh the list.
  3. Distinguish version ids (from the versions endpoint) from document/global ids.
  4. Configure version retention so you know when versions disappear.

Example fix

// before
await payload.restoreGlobalVersion({ slug, id })

// after
const { docs } = await payload.findGlobalVersions({
  slug,
  where: { id: { equals: id } },
  limit: 1,
})
if (docs.length === 0) throw new Error('version gone')
await payload.restoreGlobalVersion({ slug, id })
Defensive patterns

Strategy: validation

Validate before calling

const { docs } = await payload.findGlobalVersions({
  slug,
  where: { id: { equals: id } },
  limit: 1,
})
if (!docs.length) throw new Error('version not found')

Type guard

function versionExists(list: { id?: string | number }[], id: string | number) {
  return list.some((v) => String(v.id) === String(id))
}

Try / catch

try {
  await payload.restoreGlobalVersion({ slug, id })
} catch (err) {
  if (err instanceof NotFound) return null
  throw err
}

Prevention

When it happens

Trigger: POST /globals/:slug/versions/:id/restore or payload.restoreGlobalVersion with an id that has no matching version row, including after the version was purged or belongs to a different global.

Common situations: Restoring from a stale link after a version was deleted; passing a doc id instead of a version id; versions table truncated by a retention job.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/e25e1196b4773f8f. Report an issue: GitHub.