Fix collect_events returning None instead of empty list for empty expected list (#283)

This commit is contained in:
Adrian Lyjak
2026-01-15 15:24:15 -05:00
committed by GitHub
parent 7d982d4a93
commit bfbfba4780
4 changed files with 31 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llama-index-workflows": patch
---
Return an empty list for empty target events, rather than None
@@ -237,6 +237,10 @@ class WorkflowBroker(Generic[MODEL_T]):
) -> list[Event] | None:
step_ctx = self._get_step_ctx(fn="collect_events")
# If no events are expected, return an empty list immediately
if not expected:
return []
buffer_id = buffer_id or "default"
collected_events = step_ctx.state.collected_events.get(buffer_id, [])
@@ -57,6 +57,26 @@ async def test_collect_events() -> None:
assert r.result == [ev1, ev2]
@pytest.mark.asyncio
async def test_collect_events_empty_expected_list() -> None:
"""
Test that collect_events returns an empty list (not None) when the
expected list is empty. This edge case should immediately return []
since there are no events to collect.
"""
class TestWorkflow(Workflow):
@step
async def start_step(self, ctx: Context, ev: StartEvent) -> StopEvent:
# Pass an empty list of expected events
events = ctx.collect_events(ev, [])
# Should return an empty list, not None
return StopEvent(result=events)
r = await WorkflowTestRunner(TestWorkflow()).run()
assert r.result == []
@pytest.mark.asyncio
async def test_collect_events_with_extra_event_type() -> None:
"""
Generated
+2 -2
View File
@@ -1644,7 +1644,7 @@ wheels = [
[[package]]
name = "llama-index-utils-workflow"
version = "0.7.0"
version = "0.7.1"
source = { editable = "packages/llama-index-utils-workflow" }
dependencies = [
{ name = "llama-index-core" },
@@ -1677,7 +1677,7 @@ dev = [
[[package]]
name = "llama-index-workflows"
version = "2.12.0"
version = "2.12.1"
source = { editable = "packages/llama-index-workflows" }
dependencies = [
{ name = "eval-type-backport", marker = "python_full_version < '3.10'" },