Skip to content

fix: coerce schedulePublish doc.value to collection ID type before update - #17238

Merged
JessRynkar merged 1 commit into
payloadcms:3.xfrom
aevarOrigo:fix/schedule-publish-numeric-id-nested-docs-3x
Jul 9, 2026
Merged

JessRynkar merged 1 commit into
payloadcms:3.xfrom
aevarOrigo:fix/schedule-publish-numeric-id-nested-docs-3x

Conversation

@aevarOrigo

Copy link
Copy Markdown
Contributor

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

…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
@aevarOrigo

Copy link
Copy Markdown
Contributor Author

Note: closed the main-branch PR (#17236) this was backporting from — this 3.x fix is the one that actually ships in a release, so keeping just this one open.

@JessRynkar JessRynkar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Appropriate fix and consistent with how ID coercion is handled elsewhere in the codebase.

@JessRynkar
JessRynkar enabled auto-merge (squash) July 9, 2026 11:23
@JessRynkar
JessRynkar merged commit 7de11b2 into payloadcms:3.x Jul 9, 2026
343 of 345 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.86.0

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.

2 participants