(cherry picked from commit b8ed8d624c
)
version-14
@@ -152,8 +152,9 @@ class BaseDocument: | |||||
if "name" in d: | if "name" in d: | ||||
self.name = d["name"] | self.name = d["name"] | ||||
ignore_children = hasattr(self, "flags") and self.flags.ignore_children | |||||
for key, value in d.items(): | for key, value in d.items(): | ||||
self.set(key, value) | |||||
self.set(key, value, as_value=ignore_children) | |||||
return self | return self | ||||
@@ -129,6 +129,7 @@ class Document(BaseDocument): | |||||
def load_from_db(self): | def load_from_db(self): | ||||
"""Load document and children from database and create properties | """Load document and children from database and create properties | ||||
from fields""" | from fields""" | ||||
self.flags.ignore_children = True | |||||
if not getattr(self, "_metaclass", False) and self.meta.issingle: | if not getattr(self, "_metaclass", False) and self.meta.issingle: | ||||
single_doc = frappe.db.get_singles_dict(self.doctype, for_update=self.flags.for_update) | single_doc = frappe.db.get_singles_dict(self.doctype, for_update=self.flags.for_update) | ||||
if not single_doc: | if not single_doc: | ||||
@@ -150,6 +151,7 @@ class Document(BaseDocument): | |||||
) | ) | ||||
super().__init__(d) | super().__init__(d) | ||||
self.flags.pop("ignore_children", None) | |||||
for df in self._get_table_fields(): | for df in self._get_table_fields(): | ||||
# Make sure not to query the DB for a child table, if it is a virtual one. | # Make sure not to query the DB for a child table, if it is a virtual one. | ||||
@@ -375,6 +375,12 @@ class TestDocument(FrappeTestCase): | |||||
doc.set("user_emails", None) | doc.set("user_emails", None) | ||||
self.assertEqual(doc.user_emails, []) | self.assertEqual(doc.user_emails, []) | ||||
# setting a string value should fail | |||||
self.assertRaises(TypeError, doc.set, "user_emails", "fail") | |||||
# but not when loading from db | |||||
doc.flags.ignore_children = True | |||||
doc.update({"user_emails": "ok"}) | |||||
def test_doc_events(self): | def test_doc_events(self): | ||||
"""validate that all present doc events are correct methods""" | """validate that all present doc events are correct methods""" | ||||