Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: requested group ids arrays must be of same length #9038

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down