Repository navigation
fix: delete scheduled publish jobs queued with a string document id #19450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4683,6 +4683,98 @@ describe('Versions', () => { | |
| }) | ||
| }) | ||
|
|
||
| it('should delete scheduled jobs queued with a string ID after a document is deleted', async () => { | ||
| const draft = await payload.create({ | ||
| collection: draftCollectionSlug, | ||
| data: { | ||
| description: 'hello', | ||
| title: 'my doc to publish in the future', | ||
| }, | ||
| draft: true, | ||
| }) | ||
|
|
||
| const currentDate = new Date() | ||
|
|
||
| await payload.jobs.queue({ | ||
| input: { | ||
| type: 'publish', | ||
| doc: { | ||
| relationTo: draftCollectionSlug, | ||
| value: String(draft.id), | ||
| }, | ||
| }, | ||
| task: 'schedulePublish', | ||
| waitUntil: new Date(currentDate.getTime() + 3000), | ||
| }) | ||
|
|
||
| await payload.delete({ | ||
| id: draft.id, | ||
| collection: draftCollectionSlug, | ||
| }) | ||
|
|
||
| const { docs } = await payload.find({ | ||
| collection: 'payload-jobs', | ||
| where: { | ||
| 'input.doc.value': { | ||
| equals: String(draft.id), | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| expect(docs[0]).toBeUndefined() | ||
|
|
||
| await cleanupDocuments({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| collectionSlugs: [draftCollectionSlug, 'payload-jobs'], | ||
| payload, | ||
| }) | ||
| }) | ||
|
|
||
| it('should delete scheduled jobs after a document is deleted by a string ID', async () => { | ||
| const draft = await payload.create({ | ||
| collection: draftCollectionSlug, | ||
| data: { | ||
| description: 'hello', | ||
| title: 'my doc to publish in the future', | ||
| }, | ||
| draft: true, | ||
| }) | ||
|
|
||
| const currentDate = new Date() | ||
|
|
||
| await payload.jobs.queue({ | ||
| input: { | ||
| type: 'publish', | ||
| doc: { | ||
| relationTo: draftCollectionSlug, | ||
| value: draft.id, | ||
| }, | ||
| }, | ||
| task: 'schedulePublish', | ||
| waitUntil: new Date(currentDate.getTime() + 3000), | ||
| }) | ||
|
|
||
| await payload.delete({ | ||
| id: String(draft.id), | ||
| collection: draftCollectionSlug, | ||
| }) | ||
|
|
||
| const { docs } = await payload.find({ | ||
| collection: 'payload-jobs', | ||
| where: { | ||
| 'input.doc.value': { | ||
| equals: draft.id, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| expect(docs[0]).toBeUndefined() | ||
|
|
||
| await cleanupDocuments({ | ||
| collectionSlugs: [draftCollectionSlug, 'payload-jobs'], | ||
| payload, | ||
| }) | ||
| }) | ||
|
|
||
| it('should allow global scheduled publish', async () => { | ||
| const draft = await payload.updateGlobal({ | ||
| slug: draftGlobalSlug, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: payloadcms/payload
Length of output: 3659
Script executed:
Repository: payloadcms/payload
Length of output: 30028
Script executed:
Repository: payloadcms/payload
Length of output: 6449
Script executed:
Repository: payloadcms/payload
Length of output: 22285
Script executed:
Repository: payloadcms/payload
Length of output: 11901
Script executed:
Repository: payloadcms/payload
Length of output: 8304
Script executed:
Repository: payloadcms/payload
Length of output: 17235
Script executed:
Repository: payloadcms/payload
Length of output: 11320
Script executed:
Repository: payloadcms/payload
Length of output: 8148
Preserve the requested ID in the cleanup filter.
If a job stores
"01"and deletion uses"01", cleanup can leave the job. If SQLite reuses ID1, the job can publish the replacement document.Suggested fix