Skip to content

Commit d8526a2

Browse files
committed
fix: Executing <initial> content on default entry
1 parent 0e43ed4 commit d8526a2

5 files changed

Lines changed: 13 additions & 102 deletions

File tree

statemachine/engines/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def _execute_transition_content(
385385

386386
return result
387387

388-
def _enter_states(
388+
def _enter_states( # noqa: C901
389389
self,
390390
enabled_transitions: List[Transition],
391391
trigger_data: TriggerData,
@@ -425,8 +425,6 @@ def _enter_states(
425425
if self.sm.atomic_configuration_update:
426426
self.sm.configuration = new_configuration
427427

428-
# Sort states to enter in entry order
429-
# for state in sorted(states_to_enter, key=self.entry_order): # TODO: order of states_to_enter # noqa: E501
430428
for info in ordered_states:
431429
target = info.target
432430
assert target
@@ -437,6 +435,7 @@ def _enter_states(
437435
target=target,
438436
)
439437

438+
logger.debug("Entering state: %s", target)
440439
# Add state to the configuration
441440
if not self.sm.atomic_configuration_update:
442441
self.sm.configuration |= {target}
@@ -453,9 +452,12 @@ def _enter_states(
453452
on_entry_result = self.sm._callbacks.call(target.enter.key, *args, **kwargs)
454453

455454
# Handle default initial states
456-
# TODO: Handle default initial states
457-
# if state in states_for_default_entry:
458-
# self.execute_content(state.initial.transition)
455+
if target.id in {t.target.id for t in states_for_default_entry if t.target}:
456+
initial_transitions = [t for t in target.transitions if t.initial]
457+
if len(initial_transitions) == 1:
458+
result += self.sm._callbacks.call(
459+
initial_transitions[0].on.key, *args, **kwargs
460+
)
459461

460462
# Handle default history states
461463
# if state.id in default_history_content:

tests/scxml/w3c/mandatory/test412.fail.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/scxml/w3c/mandatory/test412.scxml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<?xml version="1.0" encoding="UTF-8"?><!-- test that executable content in the <initial> transition
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- test that executable content in the <initial> transition
23
executes after the onentry handler on the state
3-
and before the onentry handler of the child states. Event1, event2, and event3 should occur in that
4+
and before the onentry handler of the child states.
5+
Event1, event2, and event3 should occur in that
46
order. -->
57
<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:conf="http://www.w3.org/2005/scxml-conformance"
68
initial="s0" version="1.0" datamodel="python">

tests/scxml/w3c/mandatory/test525.fail.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/scxml/w3c/mandatory/test525.scxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the iteration behavior.-->
1111
<state id="s0">
1212
<onentry>
1313
<foreach array="Var1" item="Var3">
14-
<assign expr="Var1 + '4'" location="Var1" />
14+
<assign expr="Var1 + ['4']" location="Var1" />
1515
<assign expr="Var2 + 1" location="Var2" />
1616
</foreach>
1717
</onentry>

0 commit comments

Comments
 (0)