Skip to content

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

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

JessRynkar merged 1 commit into
payloadcms:mainfrom
aevarOrigo:fix/schedule-publish-numeric-id-nested-docs

Conversation

@aevarOrigo

Copy link
Copy Markdown
Contributor

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

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 a regression test in test/plugin-nested-docs/int.spec.ts (enabled schedulePublish: true on that project's pages fixture collection, which is 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 — since calling payload.jobs.queue()/schedulePublishHandler directly from Node passes a native number and doesn't trigger the bug on its own.

Verified locally against Postgres:

  • 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 aevarOrigo changed the title fix(schedulePublish): coerce doc.value to collection ID type before update fix: coerce schedulePublish doc.value to collection ID type before update Jul 8, 2026
@aevarOrigo

Copy link
Copy Markdown
Contributor Author

3.x backport: #17238

@aevarOrigo

Copy link
Copy Markdown
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.

@aevarOrigo aevarOrigo closed this Jul 8, 2026
@JessRynkar JessRynkar reopened this Jul 9, 2026
@JessRynkar

Copy link
Copy Markdown
Member

@aevarOrigo thank you for getting these changes done across v3 and v4. We will want the same fix here, approved ✅

@JessRynkar
JessRynkar enabled auto-merge (squash) July 9, 2026 11:23
@JessRynkar
JessRynkar merged commit d245ab8 into payloadcms:main Jul 9, 2026
278 of 286 checks passed
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
```
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.

schedulePublish task fails with "invalid relationships" on collections using @payloadcms/plugin-nested-docs breadcrumbs (Postgres, numeric IDs)

2 participants