Fix fsm.update messages being thiggered without a state change

This commit is contained in:
Kristóf Tóth 2019-12-19 13:58:48 +01:00
parent 269cab691e
commit c8d4080ef5

View File

@ -1,6 +1,7 @@
import logging
from collections import defaultdict
from datetime import datetime
from contextlib import suppress
from transitions import Machine, MachineError
@ -62,14 +63,12 @@ class FSMBase(Machine, CallbackMixin):
)
if all(predicate_results):
try:
with suppress(AttributeError, MachineError):
from_state = self.state
self.trigger(trigger)
self.update_event_log(from_state, trigger)
return True
except (AttributeError, MachineError):
LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger)
return False
if self.trigger(trigger):
self.update_event_log(from_state, trigger)
return True
LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger)
def update_event_log(self, from_state, trigger):
self.event_log.append({