Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code de4ffbd554 Date filter passes string "null" to SQL instead of using IS NULL condition
https://sonarly.com/issue/6393?type=bug

A dashboard bar chart widget fails when a DATE filter has operand "IS" with the literal string "null" as value, which PostgreSQL rejects as an invalid date.

Fix: ## Root Cause

When a dashboard chart widget has a DATE filter with `operand: "IS"` and `value: "null"` (the literal string `"null"`), the `checkIfShouldSkipFiltering` function did not recognize `"null"` as an empty/missing value. It only checked for `undefined`, `null` (JS null), and `''`. The string `"null"` slipped through all guards and reached the SQL query builder, which emitted `WHERE "expectedCloseDate" = $1` with `$1 = "null"` — a value PostgreSQL rejects as an invalid date.

## Fix

Added `recordFilter.value === 'null'` to the emptiness check in `checkIfShouldSkipFiltering`:

```typescript file=packages/twenty-shared/src/utils/filter/checkIfShouldSkipFiltering.ts lines=20-23
  const isFilterValueEmpty =
    !isDefined(recordFilter.value) ||
    recordFilter.value === '' ||
    recordFilter.value === 'null';
```

When `value` is the string `"null"` and the operand is not an emptiness operand (`IS_EMPTY`/`IS_NOT_EMPTY`) or a no-value date operand, `shouldSkipFiltering` becomes `true` and the filter is silently skipped — preventing the invalid SQL parameter from ever reaching PostgreSQL.

This matches the existing behavior for JS `null` / `undefined` / `''` and handles the coercion case where a JS `null` was serialized to the string `"null"` before being stored in the widget configuration.
2026-03-08 17:57:53 +00:00
@@ -18,7 +18,9 @@ export const checkIfShouldSkipFiltering = ({
].includes(recordFilter.operand);
const isFilterValueEmpty =
!isDefined(recordFilter.value) || recordFilter.value === '';
!isDefined(recordFilter.value) ||
recordFilter.value === '' ||
recordFilter.value === 'null';
const shouldSkipFiltering =
!isAnEmptinessOperand && !isDateOperandWithoutValue && isFilterValueEmpty;