Files
twenty/packages/twenty-server
Thomas Trompette cb338962f5 fix(server): preserve null values in record update util (#23639)
## Problem

Record updates through the MCP server silently drop `null` values.
Setting a field to `null` (to clear it) returns success but changes
nothing.

## Root cause

`removeUndefinedFromRecord` is called by `UpdateRecordService.execute`
before the DB write. It used `isDefined(value)` to decide what to strip,
but `isDefined` returns false for **both** `undefined` and `null`:

```ts
export const isDefined = (value) => !isUndefined(value) && !isNull(value);
```

So despite the name (and the comment stating the validation layer
expects "a value or null"), the util also discarded `null`. The MCP
`update_one` path deliberately keeps nulls (it filters only `!==
undefined`), but this util then removed them one layer down.

The workflow UPDATE_RECORD action was less affected because it passes an
explicit `fieldsToUpdate` list, but the value-level strip sits on both
paths.

## Fix

Strip only `undefined`; preserve `null` so a field can be explicitly
cleared. Added unit tests covering undefined stripping, null
preservation, and nested composite fields.

## Test

```
npx jest remove-undefined-from-record
# 5 passed
```

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/23639?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
2026-07-31 13:36:49 +00:00
..