From 759a4af8e610f4a55551f2bbab4a7a498a97cb2a Mon Sep 17 00:00:00 2001 From: filou Date: Sat, 30 Nov 2024 16:36:11 +0100 Subject: [PATCH] Hotfix: requested group ids arrays must be of same length Description --- Fixes issue from [this kind of monitor](https://dust4ai.slack.com/archives/C05F84CFP0E/p1732945133294399) The longer term fix would be to store requested ids differently: - either as string[] with comma-separated values; - or as a JSONB object Risks --- na Deploy --- front --- front/lib/api/assistant/conversation.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/front/lib/api/assistant/conversation.ts b/front/lib/api/assistant/conversation.ts index 1614a5ebcd98..6c02ab8e5bb6 100644 --- a/front/lib/api/assistant/conversation.ts +++ b/front/lib/api/assistant/conversation.ts @@ -2152,9 +2152,26 @@ export async function updateConversationRequestedGroupIds( ...requirementsToAdd.map((req) => sortBy(req.map(getModelId))), ]; + // Hotfix: Postgres requires all subarrays to be of the same length + // + // since a requirement (subarray) is a set of groups that are linked with OR + // logic we can just repeat the last element of each requirement until all + // requirements have the maximal length. + const longestRequirement = allRequirements.reduce( + (max, req) => Math.max(max, req.length), + 0 + ); + // for each requirement, repeatedly add the last id until array is of longest requirement length + const updatedRequirements = allRequirements.map((req) => { + while (req.length < longestRequirement) { + req.push(req[req.length - 1]); + } + return req; + }); + await Conversation.update( { - requestedGroupIds: allRequirements, + requestedGroupIds: updatedRequirements, }, { where: {