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
4 changes: 3 additions & 1 deletion src/node_graph/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,12 @@ def _set_socket_value(self, value: Any, *, value_source: str = "link") -> None:
)

def _serialize_value(self, store: bool = False) -> Any:
"""Serialize the socket value unless it's metadata (stored as raw)."""
value = _unwrap_tagged_value(self._value)
if value is None:
return None
if self._metadata.is_metadata:
return value
graph = getattr(self, "_graph", None)
if graph is None and getattr(self, "_task", None) is not None:
graph = getattr(self._task, "graph", None)
Expand Down Expand Up @@ -1070,7 +1073,6 @@ def _collect_values(
else:
value = item.value if resolve else item._value
if serialize:
print("socket: ", item)
value = item._serialize_value(store=False)
if value is not None:
if unwrap and isinstance(value, TaggedValue):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,27 @@ def _serialize_value(self, store: bool = False):
data = task.to_dict(should_serialize=True)
assert data["inputs"]["x"] == {"custom": 5}
assert data["inputs"]["y"] == 7


def test_metadata_socket_skips_serialization():
"""Metadata sockets should bypass serialization."""
from typing import Annotated

from node_graph import Graph, task
from node_graph.socket_spec import meta

class DummySerializer:
def serialize(self, value, socket, *, store: bool):
return {"serialized": value}

@task()
def add(x: int, info: Annotated[int, meta(is_metadata=True)]):
return x

ng = Graph(name="test_metadata_socket", serialization=DummySerializer())
node = ng.add_task(add, name="add1")
node.set_inputs({"x": 2, "info": 9})

data = node.to_dict(should_serialize=True)
assert data["inputs"]["x"] == {"serialized": 2}
assert data["inputs"]["info"] == 9