Repository navigation
Patch Payload to parse multipart saves that arrive without Content-Length - #1253
Merged
Merged
Conversation
…ngth Admin saves and photo uploads have been intermittently 500ing in production with `Cannot read properties of undefined (reading '_status')`, and on the publish path with `(reading 'title')`. Payload's `addDataAndFileToRequest` only parses a multipart body when a truthy `Content-Length` is present. Vercel's edge intermittently forwards admin PATCHes with `Transfer-Encoding: chunked` and no `Content-Length`, so the multipart branch is skipped, `req.data` stays undefined, and `updateDocument` throws on its unguarded `data._status` read. Retrying usually succeeds, which is why it reads as random. This is upstream payloadcms/payload#16351, fixed by #16301 and released in 3.84.0. We are pinned to 3.81.0 across all @payloadcms packages, so this carries the shipped fix as a pnpm patch rather than taking a seven-minor upgrade days before the NWAC launch. The patched region is byte-identical to 3.84.0. Upgrade and drop the patch after launch. The test fails against unpatched 3.81.0 (`req.data` is undefined) and passes with the patch, so it catches the patch silently failing to apply on a future upgrade. Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
The drift gate has been red on main since #1231, which bumped actions/github-script from v7 to v8 in pr-visual-recap.yml without re-linking the doc bound to it. Reviewed docs/agents/triage-labels.md against the current workflow: the gate thresholds it documents (25+ files or 1500+ changed lines), the sensitive-path list, and the precedence of no-visual-recap over visual-recap all still match. Nothing in the doc needed changing, so this just refreshes the binding signature. Unrelated to the Payload patch on this branch; included because the gate blocks the PR. Co-Authored-By: Claude Opus 5 <[email protected]>
2 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Production admin saves and photo uploads have been intermittently 500ing for NWAC staff with
Cannot read properties of undefined (reading '_status'), and on the publish path with(reading 'title'). This carries the upstream fix as a pnpm patch.Payload's
addDataAndFileToRequestonly parses a multipart body when a truthyContent-Lengthis present:Every admin document save is a
multipart/form-dataPATCH carrying the document JSON in a_payloadfield. Vercel's edge intermittently forwards those withTransfer-Encoding: chunkedand noContent-Length, so the branch is skipped,req.datastaysundefined, andcollections/operations/utilities/update.jsthrows on its unguardeddata._statusread. Retrying ~30s later usually succeeds, which is why it reads as random rather than as a deploy regression.This is payloadcms/payload#16351, fixed by #16301 and released in 3.84.0. We pin every
@payloadcms/*package to 3.81.0.Why patch instead of upgrade. 3.81.0 → 3.88.0 is seven minors that touch the storage adapters and both of our existing patches —
@payloadcms/storage-vercel-blobwould need to be retired (upstream shipped its ownallowOverwritein 3.87.0) and@payloadcms/plugin-mcpre-cut. That is real surface days before the NWAC launch, and nothing else in the range is urgent. The patched region here is byte-identical to 3.84.0, verified by diffing the published tarballs. Upgrade to 3.88.0 and delete this patch after launch.Related Issues
None open for this specific error. It is distinct from #1248 — Database issue with NWAC page? and #1249 — Media deletes are unguarded — dangling references block publish with an unexplained validation error, both of which were diagnosed separately on page 43.
Key Changes
patches/payload.patch— two lines indist/utilities/addDataAndFileToRequest.js, adding thehasBodyStreamfallback so a multipart body is parsed when it has a body stream but noContent-Length. Payload ships nosrc/, sodistis the whole surface.package.json/pnpm-lock.yaml— register the patch. The lockfile churn is entirely the[email protected]resolution key gaining the patch hash and cascading to dependents.__tests__/server/multipartWithoutContentLength.server.test.ts— regression coverage.How to test
The test drives the real
addDataAndFileToRequestwith a chunked multipart request. I verified it discriminates by temporarily removing the patch entry and reinstalling:Content-LengthContent-Lengthreq.dataisundefinedSo it fails loudly if the patch ever stops applying — which is exactly what should happen when we upgrade past 3.84.0 and this file should then be deleted along with the patch.
Gates run locally:
pnpm tsc,pnpm lint,pnpm prettify,pnpm verify-type-assertions, and the full suite (76 suites, 659 tests). The test uses a described@ts-expect-errorrather than anasassertion, so the assertion ratchet is unchanged — a faithfulPayloadRequestmock would need a live Payload instance.Screenshots / Demo video
n/a — the user-visible change is the error no longer occurring.
Migration Explanation
None. No schema change.
Future enhancements / Questions
handle concurrent autosave write conflicts gracefully(3.83.0),follow redirects when fetching uploaded files for MIME type detection(3.85.1), and several drizzle fixes relevant on Turso.pnpm testfrom a.claude/worktrees/*checkout discovers zero tests, becausejest.config.mjsignores/.claude/and every path in a worktree contains it. That makes the pre-commit hook fail for any commit made from a worktree — I bypassed it here after running the gates by hand. Worth fixing separately; it silently disables test coverage for agent work.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.