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
This commit is contained in:
@@ -301,7 +301,6 @@ export const updateDocument = async <
|
|||||||
data: dataToUpdate,
|
data: dataToUpdate,
|
||||||
locale,
|
locale,
|
||||||
req,
|
req,
|
||||||
select,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +320,6 @@ export const updateDocument = async <
|
|||||||
payload,
|
payload,
|
||||||
publishSpecificLocale,
|
publishSpecificLocale,
|
||||||
req,
|
req,
|
||||||
select,
|
|
||||||
snapshot: versionSnapshotResult,
|
snapshot: versionSnapshotResult,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1646,6 +1646,41 @@ describe('Select', () => {
|
|||||||
expect(doc.version.createdAt).toBeUndefined()
|
expect(doc.version.createdAt).toBeUndefined()
|
||||||
expect(doc.version.text).toBe(post.text)
|
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', () => {
|
describe('Local API - Globals', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user