Skip to content

Commit

Permalink
fix(doctype): Allow cached_property decorator in controllers (#21881)
Browse files Browse the repository at this point in the history
  • Loading branch information
cogk committed Jul 31, 2023
1 parent ada2e20 commit 2c92043
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frappe/core/doctype/doctype/doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ def validate_field_name_conflicts(self):
controller = Document

available_objects = {x for x in dir(controller) if isinstance(x, str)}
property_set = {
x for x in available_objects if isinstance(getattr(controller, x, None), property)
}
property_set = {x for x in available_objects if is_a_property(getattr(controller, x, None))}
method_set = {
x for x in available_objects if x not in property_set and callable(getattr(controller, x, None))
}
Expand Down Expand Up @@ -1795,13 +1793,18 @@ def make_module_and_roles(doc, perm_fieldname="permissions"):
raise


def is_a_property(x) -> bool:
"""Get properties (@property, @cached_property) in a controller class"""
from functools import cached_property

return isinstance(x, (property, cached_property))


def check_fieldname_conflicts(docfield):
"""Checks if fieldname conflicts with methods or properties"""
doc = frappe.get_doc({"doctype": docfield.dt})
available_objects = [x for x in dir(doc) if isinstance(x, str)]
property_list = [
x for x in available_objects if isinstance(getattr(type(doc), x, None), property)
]
property_list = [x for x in available_objects if is_a_property(getattr(type(doc), x, None))]
method_list = [
x for x in available_objects if x not in property_list and callable(getattr(doc, x))
]
Expand Down

0 comments on commit 2c92043

Please sign in to comment.