Repository navigation
fix: coerce schedulePublish doc.value to collection ID type before update - #17236
Merged
JessRynkar merged 1 commit intoJul 9, 2026
Merged
JessRynkar merged 1 commit into
JessRynkar merged 1 commit into
Conversation
…pdate input.doc.value on a schedulePublish job is always stored as a string (see payloadcms#10481, which fixed job querying against numeric Postgres IDs). The task handler passed that string straight into payload.update({ id }), which is harmless on its own but leaks into any self-referencing relationship field recomputed during the update — e.g. the breadcrumbs.doc field added by @payloadcms/plugin-nested-docs — and fails that field's relationship-ID-type validation. Adds a regression test in test/plugin-nested-docs reproducing the failure (schedulePublish on a nested-docs-enabled collection). The test explicitly stringifies the doc ID when queuing the job, matching what the real schedule-publish UI sends (client-side relationship-picker state), rather than relying on Local API calls which pass a native number and never trigger the bug. Verified: fails with "The following field is invalid: Breadcrumbs 1 > Doc" on current main, passes with this fix. Ran via: PAYLOAD_DATABASE=postgres npx vitest run --project int test/plugin-nested-docs/int.spec.ts Fixes payloadcms#17229
Contributor
Author
|
3.x backport: #17238 |
Contributor
Author
|
Closing this one — the fix that actually matters is the 3.x backport in #17238 (the branch that ships releases). Leaving the main-branch port to the Payload team if/when they want it there. |
Member
|
@aevarOrigo thank you for getting these changes done across v3 and v4. We will want the same fix here, approved ✅ |
JessRynkar
approved these changes
Jul 9, 2026
JessRynkar
enabled auto-merge (squash)
July 9, 2026 11:23
JessRynkar
pushed a commit
that referenced
this pull request
Jul 9, 2026
…date (#17238) 3.x backport of #17236. Fixes #17229 ### What happened `input.doc.value` on a `schedulePublish` job is always stored as a string (#10481, which fixed job querying against numeric Postgres IDs by casting the stored value to string). `getSchedulePublishTask`'s handler passed that string straight into `payload.update({ id: input.doc.value, ... })` without coercing it back to the collection's real ID type. That's harmless on its own, but it leaks into any self-referencing relationship field recomputed during the update — e.g. the `breadcrumbs.doc` field added by `@payloadcms/plugin-nested-docs` — and fails that field's relationship-ID-type validation (`isValidID` requires `typeof value === 'number'` for numeric ID collections). Full repro/root-cause writeup is in #17229. ### The fix Same as #17236, adapted to this branch's version of `job.ts` (which still uses `publishSpecificLocale` rather than the simplified `locale` param on `main`): compute the target collection's real ID type and coerce `input.doc.value` to a `number` when needed, before passing it as `id` to `payload.update()`. ### Test plan Added the same regression test as #17236 in `test/plugin-nested-docs/int.spec.ts` (enabled `schedulePublish: true` on that project's `pages` fixture collection, already wired into `nestedDocsPlugin`). The test explicitly does `value: String(draft.id)` when queuing the job, matching what the real schedule-publish UI sends via client-side relationship-picker state. Verified locally against Postgres on this branch specifically: - Reverting just the `job.ts` fix reproduces the exact reported error: `Error: The following field is invalid: Breadcrumbs 1 > Doc` - With the fix, all 12 tests in `test/plugin-nested-docs/int.spec.ts` pass ``` PAYLOAD_DATABASE=postgres npx vitest run --project int test/plugin-nested-docs/int.spec.ts ```
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.
Fixes #17229
What happened
input.doc.valueon aschedulePublishjob is always stored as a string (#10481, which fixed job querying against numeric Postgres IDs by casting the stored value to string).getSchedulePublishTask's handler passed that string straight intopayload.update({ id: input.doc.value, ... })without coercing it back to the collection's real ID type.That's harmless on its own, but it leaks into any self-referencing relationship field recomputed during the update — e.g. the
breadcrumbs.docfield added by@payloadcms/plugin-nested-docs— and fails that field's relationship-ID-type validation (isValidIDrequirestypeof value === 'number'for numeric ID collections).Full repro/root-cause writeup is in #17229.
The fix
Compute the target collection's real ID type and coerce
input.doc.valueto anumberwhen needed, before passing it asidtopayload.update().Test plan
Added a regression test in
test/plugin-nested-docs/int.spec.ts(enabledschedulePublish: trueon that project'spagesfixture collection, which is already wired intonestedDocsPlugin). The test explicitly doesvalue: String(draft.id)when queuing the job — matching what the real schedule-publish UI sends via client-side relationship-picker state — since callingpayload.jobs.queue()/schedulePublishHandlerdirectly from Node passes a nativenumberand doesn't trigger the bug on its own.Verified locally against Postgres:
job.tsfix reproduces the exact reported error:Error: The following field is invalid: Breadcrumbs 1 > Doctest/plugin-nested-docs/int.spec.tspass