浏览代码

fix: ignore child tables when init-ing parent doc

(cherry picked from commit b8ed8d624c)
version-14
Ankush Menat 2 年前
committed by Ankush Menat
父节点
当前提交
84a58b3a34
共有 3 个文件被更改,包括 10 次插入1 次删除
  1. +2
    -1
      frappe/model/base_document.py
  2. +2
    -0
      frappe/model/document.py
  3. +6
    -0
      frappe/tests/test_document.py

+ 2
- 1
frappe/model/base_document.py 查看文件

@@ -152,8 +152,9 @@ class BaseDocument:
if "name" in d:
self.name = d["name"]

ignore_children = hasattr(self, "flags") and self.flags.ignore_children
for key, value in d.items():
self.set(key, value)
self.set(key, value, as_value=ignore_children)

return self



+ 2
- 0
frappe/model/document.py 查看文件

@@ -129,6 +129,7 @@ class Document(BaseDocument):
def load_from_db(self):
"""Load document and children from database and create properties
from fields"""
self.flags.ignore_children = True
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)
if not single_doc:
@@ -150,6 +151,7 @@ class Document(BaseDocument):
)

super().__init__(d)
self.flags.pop("ignore_children", None)

for df in self._get_table_fields():
# Make sure not to query the DB for a child table, if it is a virtual one.


+ 6
- 0
frappe/tests/test_document.py 查看文件

@@ -375,6 +375,12 @@ class TestDocument(FrappeTestCase):
doc.set("user_emails", None)
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):
"""validate that all present doc events are correct methods"""



正在加载...
取消
保存