From bd07ae994d8de5ce5a86044ab99ee535fbf663cb Mon Sep 17 00:00:00 2001 From: David Arnold Date: Fri, 11 Oct 2024 06:01:23 +0200 Subject: [PATCH] feat: may copy MappingProxyType (#28083) --- frappe/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 3ce7ee2c84..1b6dc3db34 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -1932,6 +1932,9 @@ def import_doc(path): def copy_doc(doc: "Document", ignore_no_copy: bool = True) -> "Document": """No_copy fields also get copied.""" import copy + from types import MappingProxyType + + from frappe.model.base_document import BaseDocument def remove_no_copy_fields(d): for df in d.meta.get("fields", {"no_copy": 1}): @@ -1943,8 +1946,10 @@ def copy_doc(doc: "Document", ignore_no_copy: bool = True) -> "Document": if not local.flags.in_test: fields_to_clear.append("docstatus") - if not isinstance(doc, dict): + if isinstance(doc, BaseDocument) or hasattr(doc, "as_dict"): d = doc.as_dict() + elif isinstance(doc, MappingProxyType): # global test record + d = dict(doc) else: d = doc