From c28e637ea752c2380dd2ac30025e7757ea5e49ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Thu, 26 Mar 2026 11:17:59 +0100 Subject: [PATCH] fix: prevent empty array `id.in` filter in single record picker (#18995) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Fixes intermittent `INVALID_QUERY_INPUT` errors (152 occurrences / 2 users in Sentry) caused by the single record picker sending `{ id: { in: [] } }` to the Search query when no records are selected - The `skip` guard is logically correct but Apollo Client v4 can briefly fire queries during React 18 render transitions before processing the skip flag - Makes `selectedIdsFilter` conditional on `hasSelectedIds`, so variables contain a safe empty filter `{}` regardless of skip behavior — matching the existing defensive pattern used by the third query's `notFilter` ## Test plan - [ ] Open a relation field picker (e.g., Person on an Opportunity) with no existing value — search should load without errors - [ ] Open a relation field picker with an existing value — selected record should appear and search should work - [ ] Clear a selected relation and reopen the picker — no console errors Made with [Cursor](https://cursor.com) --- .../hooks/useSingleRecordPickerPerformSearch.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/record-picker/single-record-picker/hooks/useSingleRecordPickerPerformSearch.ts b/packages/twenty-front/src/modules/object-record/record-picker/single-record-picker/hooks/useSingleRecordPickerPerformSearch.ts index c317aaf8b4..c4a00897cd 100644 --- a/packages/twenty-front/src/modules/object-record/record-picker/single-record-picker/hooks/useSingleRecordPickerPerformSearch.ts +++ b/packages/twenty-front/src/modules/object-record/record-picker/single-record-picker/hooks/useSingleRecordPickerPerformSearch.ts @@ -34,13 +34,16 @@ export const useSingleRecordPickerPerformSearch = ({ const { objectMetadataItems } = useObjectMetadataItems(); - const selectedIdsFilter = { id: { in: selectedIds } }; + const hasSelectedIds = selectedIds.length > 0; + const selectedIdsFilter = hasSelectedIds + ? { id: { in: selectedIds } } + : undefined; const { loading: selectedRecordsLoading, searchRecords: selectedRecords } = useObjectRecordSearchRecords({ objectNameSingulars, filter: selectedIdsFilter, - skip: !selectedIds.length, + skip: !hasSelectedIds, searchInput: '', }); @@ -50,7 +53,7 @@ export const useSingleRecordPickerPerformSearch = ({ } = useObjectRecordSearchRecords({ objectNameSingulars, filter: selectedIdsFilter, - skip: !selectedIds.length, + skip: !hasSelectedIds, searchInput: searchFilter, });