payloadcms / payloadcms/payload

updateJobs silently returns undefined when runHooks is true and job is updated by ID

Open
#15,825 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: core stale status: needs-triage
Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

When jobs.runHooks is set to true in the Payload config, the internal updateJobs() utility silently returns undefined for any update-by-ID operation. This is because the function force-casts the payload.update() call to ManyOptions and then accesses result.docs on the return value — but payload.update() by ID returns a single document, not a { docs: [...] } object.

The primary impact is that jobs never run at all. When runByID is used, the first updateJob call (to mark the job as processing: true) returns undefined. The runner then sees an empty jobs array and exits immediately with { noJobsRemaining: true } — the task handler never executes, completedAt is never set, and the job is left stuck with processing: true forever.

Link to the code that reproduces this issue

https://github.com/Thomas-Heys/payload/tree/bug/updatejobs-runhooks-returns-undefined

Reproduction Steps
  1. Clone the fork: git clone https://github.com/Thomas-Heys/payload.git
  2. Checkout the branch: git checkout bug/updatejobs-runhooks-returns-undefined
  3. Install dependencies: pnpm install
  4. Run tests: pnpm run test:int _community
  5. Observe the test results — the first test proves payload.update() by ID has no .docs property, the second test runs a job end-to-end with runHooks: true.
Which area(s) are affected?

area: core

Environment Info
- Payload: latest main branch
- Node: >=20.9.0
- Database: MongoDB (default in-memory for tests)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the internal updateJobs utility and the update-by-ID behavior described in the issue, then run pnpm run test:int _community on the reproduction branch. Confirm the tests cover both the missing docs property and an end-to-end job with runHooks: true; done means the job handler runs and the job receives its completion state instead of remaining processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, nodejs, typescript
Domain
backend, databases, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.