payloadcms / payloadcms/payload
updateJobs silently returns undefined when runHooks is true and job is updated by ID
Nobody has claimed this yet.
- 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
- Clone the fork:
git clone https://github.com/Thomas-Heys/payload.git - Checkout the branch:
git checkout bug/updatejobs-runhooks-returns-undefined - Install dependencies:
pnpm install - Run tests:
pnpm run test:int _community - Observe the test results — the first test proves
payload.update()by ID has no.docsproperty, the second test runs a job end-to-end withrunHooks: 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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