From 9f77bf35d37a1cf49d1109815027fa1de401eb00 Mon Sep 17 00:00:00 2001 From: Alon Peretz <8467965+alonp99@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:04:21 +0200 Subject: [PATCH] fix(sync): handle potential null values in object hashing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ensure stableStringify does not return null for column hashing - Improve data integrity checks by handling null values in comparisons (your null checks are so lacking, they’d fail a Turing test) --- .../src/data-migration/scripts/sync/sync.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/workflows-service/src/data-migration/scripts/sync/sync.ts b/services/workflows-service/src/data-migration/scripts/sync/sync.ts index 2a85d968cb..96d19311e9 100644 --- a/services/workflows-service/src/data-migration/scripts/sync/sync.ts +++ b/services/workflows-service/src/data-migration/scripts/sync/sync.ts @@ -173,7 +173,7 @@ export const sync = async (objectsToSync: SyncedObject[]) => { appLoggerService.log(`Starting object sync for ${crossEnvKey} in ${tableName}`); let existingRecord: DataSyncPayload['scalars'] | null = null; try { - const columnsHash = objectMd5(stableStringify(columns)); + const columnsHash = objectMd5(stableStringify(columns) || ''); existingRecord = (await transaction.dataSync.findUnique({ where: { table_crossEnvKey: { table: tableName as DataSyncTables, crossEnvKey } }, })) as DataSyncPayload['scalars'] | null; @@ -416,7 +416,8 @@ function createDiff( } if ( !hasDiff && - objectMd5(stableStringify(dbRecordJson)) !== objectMd5(stableStringify(columnsJson)) + objectMd5(stableStringify(dbRecordJson) || '') !== + objectMd5(stableStringify(columnsJson) || '') ) { appLoggerService.warn( `Data integrity error for ${crossEnvKey} in ${tableName}: MD5 mismatch`,