From 39d0e084b830bf091ea0ab1fd89a66a42a3f62fc Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 5 Oct 2020 09:59:03 +0100 Subject: [PATCH] Fixing an issue that a test case raised. --- packages/server/src/api/controllers/model.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/model.js b/packages/server/src/api/controllers/model.js index ca3f4023aa..2593002d72 100644 --- a/packages/server/src/api/controllers/model.js +++ b/packages/server/src/api/controllers/model.js @@ -24,7 +24,6 @@ exports.find = async function(ctx) { exports.save = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) - const oldModelId = ctx.request.body._id const modelToSave = { type: "model", _id: generateModelID(), @@ -32,9 +31,15 @@ exports.save = async function(ctx) { ...ctx.request.body, } // get the model in its previous state for differencing - let oldModel = null + let oldModel + let oldModelId = ctx.request.body._id if (oldModelId) { - oldModel = await db.get(oldModelId) + // if it errors then the oldModelId is invalid - can't diff it + try { + oldModel = await db.get(oldModelId) + } catch (err) { + oldModel = null + } } // rename record fields when table column is renamed