Skip to content

fix: isolate context for nested Local API calls - #17903

Open
cbratschi wants to merge 2 commits into
payloadcms:mainfrom
cbratschi:codex/fix-isolate-local-context
Open

cbratschi wants to merge 2 commits into
payloadcms:mainfrom
cbratschi:codex/fix-isolate-local-context

Conversation

@cbratschi

@cbratschi cbratschi commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

What?

Isolate req.context when a nested Local API operation explicitly supplies context, while preserving parent context values for that nested operation.

Calls that pass only req retain the existing shared operation context. This is required by recursive operations such as hierarchy path computation and its request-scoped ancestor cache.

This adds regression coverage for:

Why?

createLocalReq currently assigns an explicitly merged context directly to the provided request. A nested Local API call with its own context therefore mutates the request owned by its parent operation. Later or concurrently running sibling hooks can then observe values that belong only to the nested call.

The initial patch isolated every nested call. Full CI showed that this was too broad: Payload's hierarchy recursion passes req without a new context and intentionally shares cache updates within the operation. The corrected condition preserves that established behavior while isolating explicitly supplied child context.

How?

Use the existing isolateObjectProperty proxy only when the Local API caller supplies context. Other request state remains shared, including transaction state. Explicit child context values are shallowly merged over inherited parent values without rebinding the caller's context property.

Validated with:

  • pnpm exec vitest run --project unit packages/payload/src/utilities/createLocalReq.spec.ts — 9 tests passed
  • PAYLOAD_DATABASE=sqlite pnpm run test:int hierarchy — 35 tests passed
  • pnpm --filter payload build:types
  • focused ESLint and Prettier checks
  • git diff --check

Fixes #10250

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant