Merge pull request #28155 from gavindsouza/refactor-load_from_db

refactor: Move children load db into separate method
This commit is contained in:
Akhil Narang 2024-10-18 12:31:45 +05:30 committed by GitHub
commit bca9b27646
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -255,6 +255,15 @@ class Document(BaseDocument):
super().__init__(d)
self.flags.pop("ignore_children", None)
self.load_children_from_db()
# sometimes __setup__ can depend on child values, hence calling again at the end
if hasattr(self, "__setup__"):
self.__setup__()
return self
def load_children_from_db(self):
for df in self._get_table_fields():
# Make sure not to query the DB for a child table, if it is a virtual one.
# During frappe is installed, the property "is_virtual" is not available in tabDocType, so
@ -277,10 +286,6 @@ class Document(BaseDocument):
self.set(df.fieldname, children)
# sometimes __setup__ can depend on child values, hence calling again at the end
if hasattr(self, "__setup__"):
self.__setup__()
return self
def reload(self) -> "Self":