From 3af579498ba7fda00c8ba0148374a7369bfd68dc Mon Sep 17 00:00:00 2001 From: Corentin Date: Fri, 8 May 2026 14:08:34 +0200 Subject: [PATCH] =?UTF-8?q?fix(acadenice):=20filter=20undefined=20pageIds?= =?UTF-8?q?=20before=20sql.lit()=20in=20graph=20=E2=80=94=20Patch=20030?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit loadPageMeta logged 'invalid immediate value undefined' on every graph request. Cause: when an edge row has a null source/target_page_id (rare, but happens during partial backlink reindex), the resulting finalPageIds set carries undefined entries, and sql.lit(undefined) rejects. Filter cleanIds to string-only and return early if empty. The catch block stays as a safety net for unrelated SQL errors. Verified via curl: GET /api/acadenice/graph now returns 200 with no ERROR log line. Patch 030. --- .../core/acadenice/graph/services/graph.service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/server/src/core/acadenice/graph/services/graph.service.ts b/apps/server/src/core/acadenice/graph/services/graph.service.ts index 06081afd..18b3ec7b 100644 --- a/apps/server/src/core/acadenice/graph/services/graph.service.ts +++ b/apps/server/src/core/acadenice/graph/services/graph.service.ts @@ -424,10 +424,17 @@ export class GraphService { pageIds: string[], spaceId: string | undefined, ): Promise { - if (pageIds.length === 0) return []; + // Filter out undefined / null / empty entries before binding — sql.lit + // throws "invalid immediate value undefined" otherwise. Edges with a + // missing source/target page id would surface here when finalPageIds is + // assembled from raw rows. + const cleanIds = pageIds.filter( + (id): id is string => typeof id === 'string' && id.length > 0, + ); + if (cleanIds.length === 0) return []; try { - const idList = sql.join(pageIds.map((id) => sql.lit(id))); + const idList = sql.join(cleanIds.map((id) => sql.lit(id))); const spaceFilter = spaceId ? sql`AND sp.id = ${spaceId}` : sql``; const rows = await sql`