diff --git a/packages/drizzle/src/upsertRow/index.ts b/packages/drizzle/src/upsertRow/index.ts index 5d361610a07..2420a28221a 100644 --- a/packages/drizzle/src/upsertRow/index.ts +++ b/packages/drizzle/src/upsertRow/index.ts @@ -150,6 +150,17 @@ export const upsertRow = async | TypeWithID>( } } + // Fields such as `point` are resolved via raw SQL expressions (e.g. ST_AsGeoJSON) + // rather than plain columns, and are tracked in `findManyArgs.extras`. Without + // merging them in here, `.returning()` would either omit them or fall back to + // returning every column (including the raw, unconverted value) once selectedFields + // is non-empty but missing these keys. + if (findManyArgs.extras) { + for (const [name, extra] of Object.entries(findManyArgs.extras)) { + selectedFields[name] = extra + } + } + const docs = await drizzle .update(adapter.tables[tableName]) .set(row) diff --git a/test/fields/int.spec.ts b/test/fields/int.spec.ts index 818fd90724f..863e431cab9 100644 --- a/test/fields/int.spec.ts +++ b/test/fields/int.spec.ts @@ -1611,6 +1611,35 @@ describe('Fields', () => { expect(doc.group).toMatchObject(group) }) + it('should return point field on update by id', async () => { + if (payload.db.name === 'sqlite') { + return + } + + const created = await payload.create({ + collection: 'point-fields', + data: { + group, + localized, + point, + }, + }) + + // Update an unrelated field and ensure the point field is still + // present in the response - https://github.com/payloadcms/payload/issues/17461 + const updated = await payload.update({ + id: created.id, + collection: 'point-fields', + data: { + group, + }, + }) + + expect(updated.point).toEqual(point) + expect(updated.localized).toEqual(localized) + expect(updated.group).toMatchObject(group) + }) + it('should not create duplicate point when unique', async () => { if (payload.db.name === 'sqlite') { return