Skip to content

Commit 29bdadc

Browse files
committed
small change to match java
Signed-off-by: Tim Li <[email protected]>
1 parent 7facfa7 commit 29bdadc

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

cadence/_internal/workflow/decision_events_iterator.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class DecisionEvents:
2121
Represents events for a single decision iteration.
2222
"""
2323
events: List[HistoryEvent] = field(default_factory=list)
24-
decision_events: List[HistoryEvent] = field(default_factory=list)
2524
markers: List[HistoryEvent] = field(default_factory=list)
2625
replay: bool = False
2726
replay_current_time_milliseconds: Optional[int] = None
@@ -31,9 +30,6 @@ def get_events(self) -> List[HistoryEvent]:
3130
"""Return all events in this decision iteration."""
3231
return self.events
3332

34-
def get_decision_events(self) -> List[HistoryEvent]:
35-
"""Return decision-related events."""
36-
return self.decision_events
3733

3834
def get_markers(self) -> List[HistoryEvent]:
3935
"""Return marker events."""
@@ -43,9 +39,9 @@ def is_replay(self) -> bool:
4339
"""Check if this decision is in replay mode."""
4440
return self.replay
4541

46-
def get_optional_decision_event(self, event_id: int) -> Optional[HistoryEvent]:
47-
"""Retrieve a specific decision event by ID."""
48-
for event in self.decision_events:
42+
def get_event_by_id(self, event_id: int) -> Optional[HistoryEvent]:
43+
"""Retrieve a specific event by ID, returns None if not found."""
44+
for event in self.events:
4945
if hasattr(event, 'event_id') and event.event_id == event_id:
5046
return event
5147
return None
@@ -181,9 +177,6 @@ async def next_decision_events(self) -> DecisionEvents:
181177
self._process_decision_completion_event(event, decision_events)
182178
current_index += 1 # Move past this event
183179
break
184-
else:
185-
# Other events that are part of this decision
186-
decision_events.decision_events.append(event)
187180

188181
current_index += 1
189182

@@ -213,14 +206,6 @@ async def next_decision_events(self) -> DecisionEvents:
213206

214207
def _process_decision_completion_event(self, event: HistoryEvent, decision_events: DecisionEvents):
215208
"""Process the decision completion event and update state."""
216-
if self._is_decision_task_completed(event):
217-
# Extract decisions from the completed event if available
218-
if hasattr(event, 'decision_task_completed_event_attributes'):
219-
completed_attrs = event.decision_task_completed_event_attributes
220-
if hasattr(completed_attrs, 'decisions'):
221-
# Process decisions - they represent what the workflow decided to do
222-
for decision in completed_attrs.decisions:
223-
decision_events.decision_events.append(decision)
224209

225210
# Check if we're still in replay mode
226211
# This is determined by comparing event IDs with the current decision task's started event ID

tests/cadence/_internal/workflow/test_decision_events_iterator.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,40 @@ def test_decision_events_initialization(self):
8888
decision_events = DecisionEvents()
8989

9090
assert decision_events.get_events() == []
91-
assert decision_events.get_decision_events() == []
9291
assert decision_events.get_markers() == []
9392
assert not decision_events.is_replay()
9493
assert decision_events.replay_current_time_milliseconds is None
9594
assert decision_events.next_decision_event_id is None
9695

9796
def test_decision_events_with_data(self):
9897
"""Test DecisionEvents with actual data."""
99-
events = [create_mock_history_event(1, "decision_task_started")]
100-
decision_events = [create_mock_history_event(2, "decision_task_completed")]
98+
events = [create_mock_history_event(1, "decision_task_started"), create_mock_history_event(2, "decision_task_completed")]
10199
markers = [create_mock_history_event(3, "marker_recorded")]
102100

103101
decision_events_obj = DecisionEvents(
104102
events=events,
105-
decision_events=decision_events,
106103
markers=markers,
107104
replay=True,
108105
replay_current_time_milliseconds=123456,
109106
next_decision_event_id=4
110107
)
111108

112109
assert decision_events_obj.get_events() == events
113-
assert decision_events_obj.get_decision_events() == decision_events
114110
assert decision_events_obj.get_markers() == markers
115111
assert decision_events_obj.is_replay()
116112
assert decision_events_obj.replay_current_time_milliseconds == 123456
117113
assert decision_events_obj.next_decision_event_id == 4
118114

119-
def test_get_optional_decision_event(self):
120-
"""Test retrieving optional decision event by ID."""
115+
def test_get_event_by_id(self):
116+
"""Test retrieving event by ID."""
121117
event1 = create_mock_history_event(1, "decision_task_started")
122118
event2 = create_mock_history_event(2, "decision_task_completed")
123119

124-
decision_events = DecisionEvents(decision_events=[event1, event2])
120+
decision_events = DecisionEvents(events=[event1, event2])
125121

126-
assert decision_events.get_optional_decision_event(1) == event1
127-
assert decision_events.get_optional_decision_event(2) == event2
128-
assert decision_events.get_optional_decision_event(999) is None
122+
assert decision_events.get_event_by_id(1) == event1
123+
assert decision_events.get_event_by_id(2) == event2
124+
assert decision_events.get_event_by_id(999) is None
129125

130126

131127

@@ -374,10 +370,8 @@ async def test_complex_workflow_scenario(self, mock_client):
374370
first_decision = all_decisions[0]
375371
assert len(first_decision.get_events()) == 6 # Events 1-6
376372
assert len(first_decision.get_markers()) == 1 # Event 4
377-
assert len(first_decision.get_decision_events()) == 3 # Events 2, 3, 5
378373

379374
# Second decision should be simpler
380375
second_decision = all_decisions[1]
381376
assert len(second_decision.get_events()) == 2 # Events 7-8
382-
assert len(second_decision.get_markers()) == 0
383-
assert len(second_decision.get_decision_events()) == 0
377+
assert len(second_decision.get_markers()) == 0

0 commit comments

Comments
 (0)