Skip to content
Open
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
14 changes: 4 additions & 10 deletions src/node_graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class Graph(IOOwnerMixin, WidgetRenderableMixin):
Attributes:
name (str): The name of the task graph.
uuid (str): The UUID of this task graph.
graph_type (str): The type of the task graph.
state (str): The state of this task graph.
action (str): The action of this task graph.
platform (str): The platform used to create this task graph.
Expand Down Expand Up @@ -102,7 +101,6 @@ def __init__(
outputs: Optional[SocketSpec | List[str]] = None,
ctx: Optional[SocketSpec | List[str]] = None,
uuid: Optional[str] = None,
graph_type: str = "NORMAL",
graph: Optional[Graph] = None,
parent: Optional[Task] = None,
interactive_widget: bool = False,
Expand All @@ -116,12 +114,10 @@ def __init__(
Args:
name (str, optional): The name of the task graph. Defaults to "Graph".
uuid (str, optional): The UUID of the task graph. Defaults to None.
graph_type (str, optional): The type of the task graph. Defaults to "NORMAL".
"""

self.name = name
self.uuid = uuid or str(uuid1())
self.graph_type = graph_type
self.graph = graph
self.parent = parent
self.type_mapping = dict(self._REGISTRY.type_mapping)
Expand Down Expand Up @@ -610,16 +606,14 @@ def to_dict(

def get_metadata(self) -> Dict[str, Any]:
"""Export graph metadata including *live* graph-level IO specs."""
meta: Dict[str, Any] = {
"graph_type": self.graph_type,
}
meta: Dict[str, Any] = {}
# also save the parent class information
meta["graph_class"] = {
"callable_name": self.__class__.__name__,
"module_path": self.__class__.__module__,
}
for key, value in (self._metadata or {}).items():
if key in {"graph_type", "graph_class"}:
if key == "graph_class":
continue
meta[key] = value
return meta
Expand Down Expand Up @@ -748,15 +742,15 @@ def from_dict(cls, ngdata: Dict[str, Any]) -> Graph:
"""
spec = GraphSpec.from_dict(ngdata.get("spec", {}))
raw_meta = ngdata.get("metadata", {}) or {}
base_meta = {k: raw_meta[k] for k in ("graph_type",) if k in raw_meta}
# graph_type is discarded: old serialized graphs may still carry it,
# but nothing constructs or reads it any more.
extra_meta = {k: v for k, v in raw_meta.items() if k not in {"graph_type"}}
ng = cls(
name=ngdata["name"],
uuid=ngdata.get("uuid"),
inputs=spec.inputs,
outputs=spec.outputs,
ctx=spec.ctx,
graph_type=base_meta.get("graph_type", "NORMAL"),
metadata=extra_meta,
)
ng.state = ngdata.get("state", "CREATED")
Expand Down
11 changes: 11 additions & 0 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def test_from_dict(ng_decorator):
assert ng.to_dict() == ng1.to_dict()


def test_from_dict_discards_stale_graph_type():
"""A stored graph_type key from an old payload loads without error."""
ng = Graph(name="test_graph")
ngdata = ng.to_dict()
assert "graph_type" not in ngdata["metadata"]
ngdata["metadata"]["graph_type"] = "NORMAL"
restored = Graph.from_dict(ngdata)
assert not hasattr(restored, "graph_type")
assert "graph_type" not in restored.to_dict()["metadata"]


def test_from_dict_namespace_links():
@task()
def make_pair(x: int, y: int) -> namespace(a=int, nested=namespace(x=int, y=int)):
Expand Down
Loading