From 4565774669bc3c1b11cc726d577946953dbe53c5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Feb 2023 08:59:27 +0100 Subject: Fix retrying update on sql serialization conflict --- server/controllers/api/video-channel.ts | 6 ++---- server/controllers/api/video-playlist.ts | 6 ++---- server/controllers/api/videos/update.ts | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index d7c92952a..5b9fb794a 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts @@ -273,7 +273,6 @@ async function addVideoChannel (req: express.Request, res: express.Response) { async function updateVideoChannel (req: express.Request, res: express.Response) { const videoChannelInstance = res.locals.videoChannel - const videoChannelFieldsSave = videoChannelInstance.toJSON() const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()) const videoChannelInfoToUpdate = req.body as VideoChannelUpdate let doBulkVideoUpdate = false @@ -309,10 +308,9 @@ async function updateVideoChannel (req: express.Request, res: express.Response) } catch (err) { logger.debug('Cannot update the video channel.', { err }) - // Force fields we want to update // If the transaction is retried, sequelize will think the object has not changed - // So it will skip the SQL request, even if the last one was ROLLBACKed! - resetSequelizeInstance(videoChannelInstance, videoChannelFieldsSave) + // So we need to restore the previous fields + resetSequelizeInstance(videoChannelInstance) throw err } diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index 947f7ca77..bcb60e265 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -210,7 +210,6 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { async function updateVideoPlaylist (req: express.Request, res: express.Response) { const videoPlaylistInstance = res.locals.videoPlaylistFull - const videoPlaylistFieldsSave = videoPlaylistInstance.toJSON() const videoPlaylistInfoToUpdate = req.body as VideoPlaylistUpdate const wasPrivatePlaylist = videoPlaylistInstance.privacy === VideoPlaylistPrivacy.PRIVATE @@ -275,10 +274,9 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) } catch (err) { logger.debug('Cannot update the video playlist.', { err }) - // Force fields we want to update // If the transaction is retried, sequelize will think the object has not changed - // So it will skip the SQL request, even if the last one was ROLLBACKed! - resetSequelizeInstance(videoPlaylistInstance, videoPlaylistFieldsSave) + // So we need to restore the previous fields + resetSequelizeInstance(videoPlaylistInstance) throw err } diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 260dee2b9..e6197c4b1 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts @@ -45,7 +45,6 @@ export { async function updateVideo (req: express.Request, res: express.Response) { const videoFromReq = res.locals.videoAll - const videoFieldsSave = videoFromReq.toJSON() const oldVideoAuditView = new VideoAuditView(videoFromReq.toFormattedDetailsJSON()) const videoInfoToUpdate: VideoUpdate = req.body @@ -151,10 +150,9 @@ async function updateVideo (req: express.Request, res: express.Response) { isNewVideo }) } catch (err) { - // Force fields we want to update // If the transaction is retried, sequelize will think the object has not changed - // So it will skip the SQL request, even if the last one was ROLLBACKed! - resetSequelizeInstance(videoFromReq, videoFieldsSave) + // So we need to restore the previous fields + resetSequelizeInstance(videoFromReq) throw err } finally { -- cgit v1.2.3