Skip to content

Commit

Permalink
fix(sync): handle potential null values in object hashing
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
alonp99 committed Dec 19, 2024
1 parent 74016de commit 9f77bf3
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit 9f77bf3

Please sign in to comment.