Skip to content

req.context values shared between different payload.find*() calls if req gets passed #10250

Open

Description

@cbratschi

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

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Dec 30, 2024
  2. removed
    validate-reproduction
    on Dec 30, 2024
  3. removed
    status: needs-triage
    on Dec 30, 2024
  4. jmikrut commented on Dec 30, 2024

    @jmikrut
    Member

    On first glance, this makes sense to me. You want the context to follow through explicitly where you passed it, but right now, it's shared across all operations.

    We will need to think through this one to make sure that we can change this without any negative repercussions.

    @r1tsuu let's think through this a bit!

  5. cbratschi commented on Dec 30, 2024

    @cbratschi
    ContributorAuthor

    Could you please also have a look at: #9960

    This issue caused me a lot of headache and still need to patch every Payload version. Related to hook handling too and easy to fix.

  6. JessRynkar commented on Feb 20, 2026

    @JessRynkar
    Member

    Hi @cbratschi! Are you still experiencing this on the latest version v3.77.0?

  7. cbratschi commented on Feb 20, 2026

    @cbratschi
    ContributorAuthor

    @JessRynkar Yes, the Payload architecture is still the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions