Commit 7de11b2
authored
fix: coerce schedulePublish doc.value to collection ID type before update (#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
```1 parent 2061859 commit 7de11b2
3 files changed
Lines changed: 59 additions & 2 deletions
File tree
- packages/payload/src/versions/schedule
- test/plugin-nested-docs
- collections
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
49 | 56 | | |
50 | | - | |
| 57 | + | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
395 | 443 | | |
396 | 444 | | |
397 | 445 | | |
| |||
0 commit comments