From f1823a71abcd5a7ec9a2303a621b2bd23615e4b5 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sat, 19 Oct 2019 19:59:41 +0530 Subject: [PATCH] fix: Remove doc from cache if name changes --- index.js | 8 ++++++++ model/document.js | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/index.js b/index.js index 23a6684b..c1b60898 100644 --- a/index.js +++ b/index.js @@ -135,6 +135,14 @@ module.exports = { } }, + removeFromCache(doctype, name) { + try { + delete this.docs[doctype][name]; + } catch(e) { + console.warn(`Document ${doctype} ${name} does not exist`); + } + }, + isDirty(doctype, name) { return ( (this.docs && diff --git a/model/document.js b/model/document.js index d70ba791..400a9ea6 100644 --- a/model/document.js +++ b/model/document.js @@ -331,9 +331,14 @@ module.exports = class BaseDocument extends Observable { await this.commit(); await this.trigger('beforeInsert'); + let oldName = this.name; const data = await frappe.db.insert(this.doctype, this.getValidDict()); this.syncValues(data); + if (oldName !== this.name) { + frappe.removeFromCache(this.doctype, oldName); + } + await this.trigger('afterInsert'); await this.trigger('afterSave');