State machine contains incorrect on_exit method after transition

Bug #1809257 reported by Michal Špondr
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
automaton
Undecided
Unassigned

Bug Description

I've created a simple automaton:

        state_space = [
                {
                    'name': '0',
                    'next_states': {
                        'STA': '1'
                        },
                    'on_exit': builder.on_exit_0
                    },
                {
                    'name': '1',
                    'next_states': {
                        'STP:REDY': '0',
                        'STP:!REDY': '0'
                        },
                    'on_exit': builder.on_exit_1
                    }
                ]

        self.machine = machines.FiniteMachine.build(state_space)
        self.machine.default_start_state = '0'
        self.machine.initialize()

There are 2 on_exit methods which lead to a method in a different object. When the automaton processes events ["STA", "STP:REDY"] it correctly processes "STA" and executes builder.on_exit_0. However when the machine is in state '1' the on_exit is still set to builder.on_exit_0.

I've tried to debug it with pdb and found this:

(Pdb) print(self.pformat())
+-------+-----------+-----+----------+-----------------------------------------------------------+
| Start | Event | End | On Enter | On Exit |
+-------+-----------+-----+----------+-----------------------------------------------------------+
| 0[^] | STA | 1 | . | bam_processor.modules.batch_module.BatchBuilder.on_exit_0 |
| @1 | STP:!REDY | 0 | . | bam_processor.modules.batch_module.BatchBuilder.on_exit_1 |
| @1 | STP:REDY | 0 | . | bam_processor.modules.batch_module.BatchBuilder.on_exit_1 |
+-------+-----------+-----+----------+-----------------------------------------------------------+

and at the same time:

(Pdb) print(self._current.on_exit)
<bound method BatchBuilder.on_exit_0 of <bam_processor.modules.batch_module.BatchBuilder object at 0x7f924bab4208>>

As you can see the pformat() knows about correct on_exit_1 method while automaton.machines.FiniteMachine._current.on_exit is still set at on_exit_0.

Michal Špondr (micaai)
description: updated
Revision history for this message
Michal Špondr (micaai) wrote :

This is also suspicious to me:

        state_space = [
                {
                    'name': '0',
                    'next_states': {
                        'STA': '1'
                    },
                    'on_exit': builder.on_exit_0,
                    'on_enter': builder.on_enter_0
                },
                {
                    'name': '1',
                    'next_states': {
                        'STP:REDY': '0',
                        'STP:!REDY': '0'
                    },
                },
        ]

        # build and initialize the automaton now
        self.machine = machines.FiniteMachine.build(state_space)
        self.machine.default_start_state = '0'
        self.machine.initialize()

I've tried to add on_enter method and for that I've got this automaton:

+-------+-----------+-----+------------------------------------------------------------+-----------------------------------------------------------+
| Start | Event | End | On Enter | On Exit |
+-------+-----------+-----+------------------------------------------------------------+-----------------------------------------------------------+
| @0[^] | STA | 1 | . | bam_processor.modules.batch_module.BatchBuilder.on_exit_0 |
| 1 | STP:!REDY | 0 | bam_processor.modules.batch_module.BatchBuilder.on_enter_0 | . |
| 1 | STP:REDY | 0 | bam_processor.modules.batch_module.BatchBuilder.on_enter_0 | . |
+-------+-----------+-----+------------------------------------------------------------+-----------------------------------------------------------+

As you can see there are on_enter_0 callbacks at On Enter in state '1' while I defined it for state '0'.

Revision history for this message
Michal Špondr (micaai) wrote :

Adding prettier output of automaton for this state space:

        state_space = [
                {
                    'name': '0',
                    'next_states': {
                        'STA': '1'
                    },
                    'on_exit': builder.on_exit_0,
                    'on_enter': builder.on_enter_0
                },
                {
                    'name': '1',
                    'next_states': {
                        'STP:REDY': '0',
                        'STP:!REDY': '0'
                    },
                },
        ]

Revision history for this message
Michal Špondr (micaai) wrote :

I've got same automaton as above even if I define it this way:

        self.machine.add_state('0', on_enter=builder.on_enter_0, on_exit=builder.on_exit_0)
        self.machine.add_state('1')
        self.machine.add_transition('0', '1', 'STA')
        self.machine.add_transition('1', '0', 'STP:REDY')
        self.machine.add_transition('1', '0', 'STP:!REDY')

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Bug attachments