From 3f87d27d5d919afb749ff1cee0ffdac013ef6459 Mon Sep 17 00:00:00 2001 From: oniani1 Date: Tue, 7 Apr 2026 11:36:41 +0400 Subject: [PATCH] fix: use AND instead of OR in neq filter for null-equivalent values (#19071) Fixes #19070 The `neq` operator in `compute-where-condition-parts.ts` uses `OR` where it should use `AND` when handling null-equivalent values. Currently generates: ```sql field != '' OR field IS NOT NULL ``` For a row where `field = ''`: - `'' != ''` = false - `'' IS NOT NULL` = true - `false OR true` = true -- row incorrectly passes the filter The `eq` operator correctly uses `OR field IS NULL` because it's additive (match value or its null equivalent). By De Morgan's law, the negation `neq` needs `AND field IS NOT NULL` -- exclude if the value doesn't match AND is not a null equivalent. With the fix: ```sql field != '' AND field IS NOT NULL ``` - `'' != ''` = false, `'' IS NOT NULL` = true, `false AND true` = false -- correctly excluded - `NULL != ''` = NULL, `NULL IS NOT NULL` = false, `NULL AND false` = false -- correctly excluded - `'Alice' != ''` = true, `'Alice' IS NOT NULL` = true, `true AND true` = true -- correctly included Affects `neq` filters on TEXT fields and all composite sub-fields (firstName, lastName, primaryEmail, primaryPhoneNumber, address sub-fields, etc.) when filtering against null-equivalent values. Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com> --- .../graphql-query-runner/utils/compute-where-condition-parts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/utils/compute-where-condition-parts.ts b/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/utils/compute-where-condition-parts.ts index f390a2ee65..84a174b35d 100644 --- a/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/utils/compute-where-condition-parts.ts +++ b/packages/twenty-server/src/engine/api/graphql/graphql-query-runner/utils/compute-where-condition-parts.ts @@ -65,7 +65,7 @@ export const computeWhereConditionParts = ({ }; case 'neq': return { - sql: `${fieldReference} != :${key}${paramSuffix}${hasNullEquivalentFieldValue ? ` OR ${fieldReference} IS NOT NULL` : ''}`, + sql: `${fieldReference} != :${key}${paramSuffix}${hasNullEquivalentFieldValue ? ` AND ${fieldReference} IS NOT NULL` : ''}`, params: { [`${key}${paramSuffix}`]: value }, }; case 'gt':