payloadcms / payloadcms/payload
req.context values shared between different payload.find*() calls if req gets passed
Open
@r1tsuu is already working on this.
Since Dec 30, 2024.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
Let me first start with the reproduction case before getting into more details:
- First start a payload.find() over a collection with several matching documents.
- Context is empty here.
- Payload fetches all documents and executes all collection hooks for those documents.
- In a collection hook we call payload.findById({ context: { value: 5 }, req }). A context value is set and req is passed (using shared transactions for instance).
- So far so good for the first document of the payload.find() operation but in the hooks for the second and later documents context.value is now 5 right away.
Payload should not use the same context object through all hook operations. Context values passed to sub operations should not influence the context values are previous or still ongoing operations like the payload.find() one.
Link to the code that reproduces this issue
https://github.com/cbratschi/payload
Reproduction Steps
See above.
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Binaries:
Node: 22.12.0
npm: 10.9.0
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
payload: 3.12.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031
Available memory (MB): 65536
Available CPU cores: 16
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.
Assessment
This issue has not been assessed yet.