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
1 change: 1 addition & 0 deletions src/lfx/src/lfx/graph/vertex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def successors_ids(self) -> list[str]:
def __getstate__(self):
state = self.__dict__.copy()
state["_lock"] = None # Locks are not serializable
state["custom_component"] = None # Component instances are rebuilt and may hold non-serializable runtime state
state["built_object"] = None if isinstance(self.built_object, UnbuiltObject) else self.built_object
state["built_result"] = None if isinstance(self.built_result, UnbuiltResult) else self.built_result
return state
Expand Down
24 changes: 24 additions & 0 deletions src/lfx/tests/unit/graph/vertex/test_vertex_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
which is responsible for processing and managing parameters in vertices.
"""

import pickle
from unittest.mock import Mock
from uuid import uuid4

Expand All @@ -18,6 +19,29 @@
from lfx.utils.util import unescape_string


def test_vertex_getstate_drops_custom_component_runtime_state():
"""Graph cache serialization should rebuild component instances instead of pickling live runtime state."""

class UnpickleableComponent:
"""Component stand-in that fails if live runtime state is serialized."""

def __getstate__(self):
"""Raise when pickle tries to serialize the component instance."""
msg = "cannot pickle component runtime state"
raise TypeError(msg)

vertex = object.__new__(Vertex)
vertex._lock = Mock()
vertex.custom_component = UnpickleableComponent()
vertex.built_object = object()
vertex.built_result = object()

state = vertex.__getstate__()

assert state["custom_component"] is None
pickle.dumps(state)


@pytest.fixture
def mock_storage_service() -> Mock:
"""Create a mock storage service for testing."""
Expand Down
Loading