Skip to content

Commit 53b2c06

Browse files
committed
fix: use BoundEvent.put() for error.communication in SCXML send actions
Replace machine.send() with BoundEvent.put() for error.communication events in _send_to_invoke and create_send_action_callable. These are always called within the processing loop, so put() is sufficient and avoids unawaited coroutine warnings in AsyncEngine.
1 parent a779577 commit 53b2c06

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

statemachine/io/scxml/actions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Callable
88
from uuid import uuid4
99

10+
from ...event import BoundEvent
1011
from ...event import Event
1112
from ...event import _event_data_kwargs
1213
from ...spec_parser import InState
@@ -426,7 +427,7 @@ def _send_to_invoke(action: SendAction, invokeid: str, **kwargs):
426427
params_values[param.name] = _eval(param.expr, **kwargs)
427428
if not machine._engine._invoke_manager.send_to_child(invokeid, event, **params_values):
428429
# Per SCXML spec: if target is not reachable → error.communication
429-
machine.send("error.communication", internal=True)
430+
BoundEvent("error.communication", internal=True, _sm=machine).put()
430431

431432

432433
def create_send_action_callable(action: SendAction) -> Callable: # noqa: C901
@@ -452,7 +453,7 @@ def send_action(*args, **kwargs): # noqa: C901
452453
if target not in _valid_targets:
453454
if target and target.startswith("#_scxml_"):
454455
# Valid SCXML session reference but undispatchable → error.communication
455-
machine.send("error.communication", internal=True)
456+
BoundEvent("error.communication", internal=True, _sm=machine).put()
456457
elif target and target.startswith("#_"):
457458
# #_<invokeid> → route to invoked child session
458459
_send_to_invoke(action, target[2:], **kwargs)

tests/test_scxml_units.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ def test_sends_error_communication_when_child_not_found(self):
522522

523523
_send_to_invoke(action, "unknown", machine=machine)
524524

525-
machine.send.assert_called_once_with("error.communication", internal=True)
525+
machine._put_nonblocking.assert_called_once()
526+
trigger_data = machine._put_nonblocking.call_args[0][0]
527+
assert str(trigger_data.event) == "error.communication"
526528

527529
def test_evaluates_eventexpr(self):
528530
"""_send_to_invoke evaluates eventexpr when event is None."""
@@ -610,7 +612,9 @@ def test_send_action_callable_scxml_session_target(self):
610612

611613
send_callable(machine=machine)
612614

613-
machine.send.assert_called_once_with("error.communication", internal=True)
615+
machine._put_nonblocking.assert_called_once()
616+
trigger_data = machine._put_nonblocking.call_args[0][0]
617+
assert str(trigger_data.event) == "error.communication"
614618
machine._engine._invoke_manager.send_to_child.assert_not_called()
615619

616620

0 commit comments

Comments
 (0)