Skip to content

Commit 6486dbd

Browse files
author
Dylan Huang
committed
Refactor serialization in SqliteEventBusDatabase and update tests for event handling
- Updated the serialization of event data to exclude None values when using Pydantic models. - Modified tests to ensure event data is deserialized correctly into EvaluationRow and to clarify the behavior of event reception in local processes.
1 parent 01f4ede commit 6486dbd

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

eval_protocol/event_bus/sqlite_event_bus_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def publish_event(self, event_type: str, data: Any, process_id: str) -> None:
3636
try:
3737
# Serialize data, handling pydantic models
3838
if hasattr(data, "model_dump"):
39-
serialized_data = data.model_dump(mode="json")
39+
serialized_data = data.model_dump(mode="json", exclude_none=True)
4040
else:
4141
serialized_data = data
4242

tests/test_event_bus.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ def test_listener(event_type: str, data):
105105
# Check that the event was received
106106
assert len(received_events) == 1
107107
assert received_events[0][0] == "row_upserted"
108-
assert isinstance(received_events[0][1], EvaluationRow)
109-
assert received_events[0][1].input_metadata.row_id == "test-123"
108+
# The event data should be a dict, but it should be deserializable by EvaluationRow
109+
assert isinstance(received_events[0][1], dict)
110+
# Try to deserialize to EvaluationRow to ensure it's compatible
111+
event = EvaluationRow(**received_events[0][1])
112+
assert event.input_metadata.row_id == "test-123"
110113

111114
event_bus2.stop_listening()
112115

@@ -116,7 +119,7 @@ def test_listener(event_type: str, data):
116119
os.unlink(db_path)
117120

118121
def test_process_isolation(self):
119-
"""Test that processes don't receive their own events."""
122+
"""Test that processes receive their own events locally but not via cross-process mechanism."""
120123
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as tmp:
121124
db_path = tmp.name
122125

@@ -137,8 +140,9 @@ def test_listener(event_type: str, data):
137140
# Wait for processing
138141
time.sleep(0.2)
139142

140-
# Should not receive the event from its own process
141-
assert len(received_events) == 0
143+
# Should receive the event from its own process via local delivery
144+
assert len(received_events) == 1
145+
assert received_events[0] == ("self_event", {"test": "data"})
142146

143147
event_bus.stop_listening()
144148

0 commit comments

Comments
 (0)