From 65dc90e2b921c48d353b59b040ea8560eef06351 Mon Sep 17 00:00:00 2001 From: Sonarly Claude Code Date: Wed, 4 Mar 2026 03:27:45 +0000 Subject: [PATCH] Currency filter crashes on undefined record field during SSE cache update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sonarly.com/issue/8335?type=bug isMatchingCurrencyFilter crashes with TypeError when a record's currency field is undefined/null, breaking real-time SSE updates on the Opportunities page. Fix: The fix adds a null/undefined guard at the top of `isMatchingCurrencyFilter` in `packages/twenty-shared/src/utils/filter/utils/isMatchingCurrencyFilter.ts`. **Two changes were made to the function:** 1. The `value` parameter type was widened to include `null | undefined`, accurately reflecting what can be passed at runtime (since `record[filterKey]` in `isRecordMatchingFilter` returns `undefined` for unset composite fields). 2. An early return of `false` was added when `value` is `undefined` or `null`, using the existing `isDefined` utility that is already imported and used elsewhere in the file. ```typescript file=packages/twenty-shared/src/utils/filter/utils/isMatchingCurrencyFilter.ts lines=70-86 export const isMatchingCurrencyFilter = ({ currencyFilter, value, }: { currencyFilter: CurrencyFilter; value: | { amountMicros?: number | null; currencyCode?: string | null; } | null | undefined; }) => { if (!isDefined(value)) { return false; } // ... rest of function ``` **Why `return false`?** A record with an unset currency field does not match a currency filter — this is semantically correct (e.g., a filter for `currencyCode: { in: ['USD'] }` should not match a record that has no currency set). This mirrors how `isMatchingAmountMicrosFilter` already handles `undefined` values for the `gt`/`gte`/`lt`/`lte` cases. --- .../filter/utils/isMatchingCurrencyFilter.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/twenty-shared/src/utils/filter/utils/isMatchingCurrencyFilter.ts b/packages/twenty-shared/src/utils/filter/utils/isMatchingCurrencyFilter.ts index f3f6bab13db..95e35357777 100644 --- a/packages/twenty-shared/src/utils/filter/utils/isMatchingCurrencyFilter.ts +++ b/packages/twenty-shared/src/utils/filter/utils/isMatchingCurrencyFilter.ts @@ -72,11 +72,18 @@ export const isMatchingCurrencyFilter = ({ value, }: { currencyFilter: CurrencyFilter; - value: { - amountMicros?: number | null; - currencyCode?: string | null; - }; + value: + | { + amountMicros?: number | null; + currencyCode?: string | null; + } + | null + | undefined; }) => { + if (!isDefined(value)) { + return false; + } + const shouldMatchCurrencyCodeFilter = isDefined(currencyFilter.currencyCode); const shouldMatchAmountMicrosFilter = isDefined(currencyFilter.amountMicros);