Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/ansys/dynamicreporting/core/utils/report_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,14 @@ def validate_tree_value(value):

@staticmethod
def validate_tree(t):

def _has_non_empty_value(val):
if val is None:
return False
if isinstance(val, str):
return bool(val.strip())
return True

if type(t) != list:
raise ValueError("The tree payload must be a list of dictionaries")
for i in t:
Expand All @@ -1151,9 +1159,14 @@ def validate_tree(t):
raise ValueError("Tree payload dictionaries must have a 'value' key")
if "children" in i:
ItemREST.validate_tree(i["children"])

# validate tree value, only at the last level of the tree or if value is not empty
if len(i.get("children", [])) == 0 or (i.get("value") or "").strip():
ItemREST.validate_tree_value(i["value"])
value = i.get("value")
children = i.get("children", [])
is_leaf = len(children) == 0

if is_leaf or _has_non_empty_value(value):
ItemREST.validate_tree_value(value)

def set_payload_tree(self, t):
self.validate_tree(t)
Expand Down
Loading
Loading