Skip to content

Commit 3ad82fc

Browse files
committed
Remove computed name property from PwdFunctionNode.
1 parent 4f5f85d commit 3ad82fc

File tree

2 files changed

+11
-39
lines changed

2 files changed

+11
-39
lines changed

python_workflow_definition/src/python_workflow_definition/aiida.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,18 @@ def _m2w_create_nodes(self):
161161
f"Processing {len(self.workflow_model.nodes)} nodes from model."
162162
)
163163
for node in self.workflow_model.nodes:
164-
node_info = f"node {node.id} (name: {getattr(node, 'name', 'N/A')}, type: {node.type})"
164+
if not isinstance(node, PwdFunctionNode):
165+
node_info = f"node {node.id} (name: {getattr(node, 'name')}, type: {node.type})"
166+
else:
167+
node_info = f"node {node.id} (name: {getattr(node, 'value')}, type: {node.type})"
165168
self.logger.debug(f"Processing {node_info}.")
169+
166170
if isinstance(node, PwdFunctionNode):
167171
try:
168172
p, m = node.value.rsplit(".", 1)
169173
mod = import_module(p)
170174
func = getattr(mod, m)
171-
task_name = node.name if node.name else f"{m}_{node.id}"
175+
task_name = f"{m}_{node.id}"
172176
self.logger.debug(
173177
f"Adding task '{task_name}' for function '{node.value}' from {node_info}."
174178
)
@@ -384,6 +388,8 @@ def _m2w_create_group_io(self):
384388
f"Assigned {len(self.wg.group_inputs)} group inputs and {len(self.wg.group_outputs)} group outputs."
385389
)
386390
self.logger.info("Finished model to WorkGraph conversion.")
391+
import ipdb; ipdb.set_trace()
392+
pass
387393

388394
def _w2m_create_function_nodes(self):
389395
self.logger.debug(f"Processing {len(self.wg.tasks)} tasks.")

python_workflow_definition/src/python_workflow_definition/models.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22
from typing import List, Union, Optional, Literal, Any, Annotated, Type, TypeVar
3-
from pydantic import BaseModel, Field, field_validator, computed_field, field_serializer
3+
from pydantic import BaseModel, Field, field_validator, field_serializer
4+
from pydantic import ValidationError
45
import json
56
import logging
67

@@ -57,21 +58,6 @@ def check_value_format(cls, v: str):
5758
raise ValueError(msg)
5859
return v
5960

60-
@computed_field
61-
def name(self) -> str:
62-
"""Dynamically computes the function name from the 'value' field."""
63-
try:
64-
return self.value.rsplit(".", 1)[-1]
65-
except IndexError:
66-
msg = f"Could not extract function name from invalid FunctionNode value: '{self.value}' (ID: {self.id}). Check validation."
67-
raise ValueError(msg)
68-
except Exception as e:
69-
logger.error(
70-
f"Unexpected error computing name for FunctionNode value: '{self.value}' (ID: {self.id}): {e}",
71-
exc_info=True,
72-
)
73-
raise
74-
7561

7662
# Discriminated Union for Nodes
7763
PwdNode = Annotated[
@@ -127,7 +113,6 @@ def dump_json(
127113
self,
128114
*,
129115
indent: Optional[int] = 2,
130-
exclude_computed_function_names: bool = True,
131116
**kwargs,
132117
) -> str:
133118
"""
@@ -143,29 +128,12 @@ def dump_json(
143128
Returns:
144129
JSON string representation of the workflow.
145130
"""
146-
logger.info(
147-
f"Dumping workflow model to JSON string (indent={indent}, exclude_func_names={exclude_computed_function_names})..."
148-
)
149131

150132
# Dump the model to a dictionary first, using mode='json' for compatible types
151133
# Pass any extra kwargs (like custom 'exclude' rules for other fields)
152134
workflow_dict = self.model_dump(mode="json", **kwargs)
153135

154-
# --- Post-process the dictionary to exclude function names if requested ---
155-
if exclude_computed_function_names and "nodes" in workflow_dict:
156-
nodes_list = workflow_dict.get("nodes", [])
157-
for i, node_dict in enumerate(nodes_list):
158-
# Check type and presence of name before deleting
159-
if (
160-
isinstance(node_dict, dict)
161-
and node_dict.get("type") == "function"
162-
and "name" in node_dict
163-
):
164-
# Create a new dict without the 'name' key for immutability or modify in place
165-
# Modifying in place is usually fine here
166-
del nodes_list[i]["name"]
167-
168-
# Dump the potentially modified dictionary to a JSON string
136+
# Dump the dictionary to a JSON string
169137
try:
170138
json_string = json.dumps(workflow_dict, indent=indent)
171139
logger.info("Successfully dumped workflow model to JSON string.")
@@ -181,7 +149,6 @@ def dump_json_file(
181149
file_name: Union[str, Path],
182150
*,
183151
indent: Optional[int] = 2,
184-
exclude_computed_function_names: bool = True,
185152
**kwargs,
186153
) -> None:
187154
"""
@@ -198,7 +165,6 @@ def dump_json_file(
198165
# Pass kwargs to dump_json, which passes them to model_dump
199166
json_string = self.dump_json(
200167
indent=indent,
201-
exclude_computed_function_names=exclude_computed_function_names,
202168
**kwargs,
203169
)
204170
try:

0 commit comments

Comments
 (0)