From 670a8dd56b94819abff10ee48cc6147f04aad05e Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Tue, 27 Dec 2016 15:25:02 +0100 Subject: [PATCH] Fix error when updating objects on some platforms On some platforms. Sequelize.update() returns 0 even if the rows were found, if no fields have been changed. --- server/database/helpers.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/database/helpers.js b/server/database/helpers.js index 0b0da474..c494647b 100644 --- a/server/database/helpers.js +++ b/server/database/helpers.js @@ -201,15 +201,14 @@ module.exports = function(Database) { return utils.promiseAuto({ oldData: () => { - if(makeHistory) - return this._getPadObject(type, padId, objId); + // Fetch the old object for the history, but also to make sure that the object exists. Unfortunately, + // we cannot rely on the return value of the update() method, as on some platforms it returns 0 even + // if the object was found (but no fields were changed) + return this._getPadObject(type, padId, objId); }, update: (oldData) => { - return this._conn.model(type).update(data, { where: { id: objId, padId: padId } }).then((res) => { - if(res[0] == 0) - throw new Error(type + " " + objId + " of pad " + padId + "could not be found."); - }); + return this._conn.model(type).update(data, { where: { id: objId, padId: padId } }); }, newData: (update) => {