From 662fc45cdbb1838d71cf587167bc94b7750c51ee Mon Sep 17 00:00:00 2001 From: Jeremy Cloarec Date: Tue, 21 Apr 2026 15:24:29 +0200 Subject: [PATCH] [backend] try catch during migration to handle corrupted notes (#15493) --- ...1776164753048-note_standard_id_abstract.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/migrations/1776164753048-note_standard_id_abstract.js b/opencti-platform/opencti-graphql/src/migrations/1776164753048-note_standard_id_abstract.js index 263d9f2eddd2..d0c0d603cb9e 100644 --- a/opencti-platform/opencti-graphql/src/migrations/1776164753048-note_standard_id_abstract.js +++ b/opencti-platform/opencti-graphql/src/migrations/1776164753048-note_standard_id_abstract.js @@ -18,16 +18,21 @@ export const up = async (next) => { const callback = (notes) => { const op = notes .map((note) => { - const newId = generateStandardId(note.entity_type, note); - if (newId === note.standard_id) { + try { + const newId = generateStandardId(note.entity_type, note); + if (newId === note.standard_id) { + return []; + } + const previousStixIds = note.x_opencti_stix_ids ?? []; + const updatedStixIds = R.uniq([...previousStixIds, note.standard_id]); + return [ + { update: { _index: note._index, _id: note._id } }, + { doc: { standard_id: newId, x_opencti_stix_ids: updatedStixIds } }, + ]; + } catch (err) { + logApp.warn('[OPENCTI] Error during note rewrite, skipping', { err, note }); return []; } - const previousStixIds = note.x_opencti_stix_ids ?? []; - const updatedStixIds = R.uniq([...previousStixIds, note.standard_id]); - return [ - { update: { _index: note._index, _id: note._id } }, - { doc: { standard_id: newId, x_opencti_stix_ids: updatedStixIds } }, - ]; }) .flat(); pushAll(bulkOperations, op);