From faed3aaf26da12d47bd28f4759ed96224de35a3f Mon Sep 17 00:00:00 2001 From: Patrik <35232443+PatrikKozak@users.noreply.github.com> Date: Mon, 15 Sep 2025 17:00:04 -0400 Subject: [PATCH] fix: versions created with incomplete data when using `select` parameter (#13809) ### What? Remove `select` parameter from database operations in update operation during version creation to fix malformed version data. ### Why? The `select` parameter was being passed to `saveVersion()` in update operations, causing versions to only contain selected fields ### How? - Removed `select` parameter from `payload.db.updateOne()` calls in update operations - Removed `select` parameter from `saveVersion()` call in update operation --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211334352350013 --- .../operations/utilities/update.ts | 2 -- test/select/int.spec.ts | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/payload/src/collections/operations/utilities/update.ts b/packages/payload/src/collections/operations/utilities/update.ts index da5d7db80..e371a09a1 100644 --- a/packages/payload/src/collections/operations/utilities/update.ts +++ b/packages/payload/src/collections/operations/utilities/update.ts @@ -301,7 +301,6 @@ export const updateDocument = async < data: dataToUpdate, locale, req, - select, }) } @@ -321,7 +320,6 @@ export const updateDocument = async < payload, publishSpecificLocale, req, - select, snapshot: versionSnapshotResult, }) } diff --git a/test/select/int.spec.ts b/test/select/int.spec.ts index 6d591ea89..d1bb58802 100644 --- a/test/select/int.spec.ts +++ b/test/select/int.spec.ts @@ -1646,6 +1646,41 @@ describe('Select', () => { expect(doc.version.createdAt).toBeUndefined() expect(doc.version.text).toBe(post.text) }) + + it('should create versions with complete data when updating with select', async () => { + // First, update the post with select to only return the id field + const updatedPost = await payload.update({ + collection: 'versioned-posts', + id: postId, + data: { + text: 'updated text', + number: 999, + }, + select: {}, + }) + + // The update operation should only return the selected field + expect(updatedPost).toStrictEqual({ + id: postId, + }) + + // However, the created version should contain the complete document + const versions = await payload.findVersions({ + collection: 'versioned-posts', + where: { parent: { equals: postId } }, + sort: '-updatedAt', + limit: 1, + }) + + const latestVersion = versions.docs[0] + assert(latestVersion) + + // The version should have complete data, not just the selected fields + expect(latestVersion.version.text).toBe('updated text') + expect(latestVersion.version.number).toBe(999) + expect(latestVersion.version.array).toEqual(post.array) + expect(latestVersion.version.blocks).toEqual(post.blocks) + }) }) describe('Local API - Globals', () => {