From 89e3951587595ccdde8f7e9e36506be0cae4cae7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jul 2024 16:38:28 +0200 Subject: [PATCH] Correctly save transaction with retries --- server/core/helpers/database-utils.ts | 14 ++++++++++++-- support/doc/development/tests.md | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/server/core/helpers/database-utils.ts b/server/core/helpers/database-utils.ts index b7276bb84..374c05ddb 100644 --- a/server/core/helpers/database-utils.ts +++ b/server/core/helpers/database-utils.ts @@ -68,10 +68,20 @@ function transactionRetryer (func: (err: any, data: T) => any) { }) } -function saveInTransactionWithRetries > (model: T) { +function saveInTransactionWithRetries > (model: T) { + const changedKeys = model.changed() + if (!changedKeys) throw new Error('No changed keys found') + return retryTransactionWrapper(() => { return sequelizeTypescript.transaction(async transaction => { - await model.save({ transaction }) + try { + await model.save({ transaction }) + } catch { + // Reinit changed keys + for (const key of changedKeys) { + model.changed(key as keyof Model, true) + } + } }) }) } diff --git a/support/doc/development/tests.md b/support/doc/development/tests.md index 544b2ba2d..cc1ba09c3 100644 --- a/support/doc/development/tests.md +++ b/support/doc/development/tests.md @@ -75,6 +75,7 @@ Some env variables can be defined to disable/enable some tests: * `AKISMET_KEY`: specify an Akismet key to test akismet external PeerTube plugin * `OBJECT_STORAGE_SCALEWAY_KEY_ID` and `OBJECT_STORAGE_SCALEWAY_ACCESS_KEY`: specify Scaleway API keys to test object storage ACL (not supported by our `chocobozzz/s3-ninja` container) * `ENABLE_FFMPEG_THUMBNAIL_PIXEL_COMPARISON_TESTS=true`: enable pixel comparison on images generated by ffmpeg. Disabled by default because a custom ffmpeg version may fails the tests + * `YOUTUBE_DL_DOWNLOAD_BEARER_TOKEN`: Bearer token to download youtube-dl binary ### Debug server logs