Skip to content

fix(ui): scheduled publish not showing related events in postgres - #10481

Merged
DanRibbens merged 1 commit into
mainfrom
fix/scheduled-publish-not-showing-related-events-in-postgres
Jan 13, 2025
Merged

DanRibbens merged 1 commit into
mainfrom
fix/scheduled-publish-not-showing-related-events-in-postgres

Conversation

@paulpopus

@paulpopus paulpopus commented Jan 9, 2025 •

Copy link
Copy Markdown
Member

Since postgres uses number IDs by default, when we were storing the relationship field value with postgres we weren't able to query it

This fixes that problem by casting the ID to always a string making it safe for querying inside the JSON field

@DanRibbens

Copy link
Copy Markdown
Contributor

@paulpopus please add a description before this is merged.

@DanRibbens
DanRibbens merged commit c9584a9 into main Jan 13, 2025
@DanRibbens
DanRibbens deleted the fix/scheduled-publish-not-showing-related-events-in-postgres branch January 13, 2025 17:35
@github-actions

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.17.0

kendelljoseph pushed a commit that referenced this pull request Feb 21, 2025
…0481)

Since postgres uses number IDs by default, when we were storing the
relationship field value with postgres we weren't able to query it

This fixes that problem by casting the ID to always a string making it
safe for querying inside the JSON field
JessRynkar pushed a commit that referenced this pull request Jul 9, 2026
…date (#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

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
```
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants