mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-17 18:05:42 +02:00
fix(account): handle empty $in array to prevent PostgreSQL IN () syntax error (#10554)
* fix(account): handle empty array in $in SQL clause to prevent PostgreSQL syntax error buildWhereClause now emits FALSE for empty $in arrays instead of invalid IN () syntax. Also adds an early return in getWorkspacesInfoWithStatusByIds so callers like the GitHub/Gmail/Backup services never hit the query with an empty uuid list. Fixes #10553 Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com> * fix(account): also guard against non-array uuids in getWorkspacesInfoWithStatusByIds Per review feedback from @ArtyomSavchenko: use Array.isArray() in addition to the length check to handle runtime cases where uuids may not be an array. Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com> --------- Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com>
This commit is contained in:
@@ -176,6 +176,10 @@ implements DbCollection<T> {
|
||||
switch (operator) {
|
||||
case '$in': {
|
||||
const inVals = Object.values(qKey as object)[0]
|
||||
if (inVals.length === 0) {
|
||||
whereChunks.push('FALSE')
|
||||
break
|
||||
}
|
||||
const inVars: string[] = []
|
||||
for (const val of inVals) {
|
||||
currIdx++
|
||||
|
||||
@@ -1351,6 +1351,7 @@ export async function getWorkspacesInfoWithStatusByIds (
|
||||
db: AccountDB,
|
||||
uuids: WorkspaceUuid[]
|
||||
): Promise<WorkspaceInfoWithStatus[]> {
|
||||
if (!Array.isArray(uuids) || uuids.length === 0) return []
|
||||
const statuses = await db.workspaceStatus.find({ workspaceUuid: { $in: uuids } })
|
||||
const statusesMap = statuses.reduce<Record<string, WorkspaceStatus>>((sm, s) => {
|
||||
sm[s.workspaceUuid] = s
|
||||
|
||||
Reference in New Issue
Block a user