From f93b87ddd845d423c3b0953e2dfe9cc44dd428b9 Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Fri, 2 May 2025 12:17:00 +0530 Subject: [PATCH] fix(Document): improve `__onload` implementation --- frappe/model/document.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frappe/model/document.py b/frappe/model/document.py index bd44c424ca..ee39426e87 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -1696,16 +1696,20 @@ class Document(BaseDocument, DocRef): else: return [] + @property + def __onload(self): + onload = self.get("__onload") + if onload is None: + onload = frappe._dict() + self.set("__onload", onload) + + return onload + def set_onload(self, key, value): - if not self.get("__onload"): - self.set("__onload", frappe._dict()) - self.get("__onload")[key] = value + self.__onload[key] = value def get_onload(self, key=None): - if not key: - return self.get("__onload", frappe._dict()) - - return self.get("__onload")[key] + return self.__onload[key] if key else self.__onload def queue_action(self, action, **kwargs): """Run an action in background. If the action has an inner function,