fix: autosave: true doesn't work on payload.update with where (#14001)

Fixes https://github.com/payloadcms/payload/issues/13952
This commit is contained in:
Sasha
2025-10-01 21:30:53 +03:00
committed by GitHub
parent d017499b86
commit 5d86d5c486
2 changed files with 53 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ import { updateDocument } from './utilities/update.js'
import { buildAfterOperation } from './utils.js'
export type Arguments<TSlug extends CollectionSlug> = {
autosave?: boolean
collection: Collection
data: DeepPartial<RequiredDataFromCollectionSlug<TSlug>>
depth?: number
@@ -91,6 +92,7 @@ export const updateOperation = async <
}
const {
autosave = false,
collection: { config: collectionConfig },
collection,
depth,
@@ -241,7 +243,7 @@ export const updateOperation = async <
const updatedDoc = await updateDocument({
id,
accessResults: accessResult,
autosave: false,
autosave,
collectionConfig,
config,
data: deepCopyObjectSimple(data),

View File

@@ -395,6 +395,56 @@ describe('Versions', () => {
})
expect(resFromVersions?.version.blocks[0]?.array[0]?.relationship).toEqual(post.id)
})
it('should not create new versions with autosave:true', async () => {
const post = await payload.create({
collection: 'autosave-posts',
data: { title: 'post', description: 'description', _status: 'draft' },
draft: true,
})
await payload.update({
collection: 'autosave-posts',
id: post.id,
draft: true,
autosave: true,
data: { title: 'autosave' },
})
const getVersionsCount = async () => {
const { totalDocs: versionsCount } = await payload.countVersions({
collection: 'autosave-posts',
where: {
parent: { equals: post.id },
},
})
return versionsCount
}
expect(await getVersionsCount()).toBe(2)
// id
await payload.update({
collection: 'autosave-posts',
id: post.id,
draft: true,
autosave: true,
data: { title: 'post-updated-1' },
})
expect(await getVersionsCount()).toBe(2)
// where
await payload.update({
collection: 'autosave-posts',
where: { id: { equals: post.id } },
draft: true,
autosave: true,
data: { title: 'post-updated-2' },
})
expect(await getVersionsCount()).toBe(2)
})
})
describe('Restore', () => {