Skip to content

Commit

Permalink
Bump python-statemachine from 1.0.3 to 2.3.1 (#85)
Browse files Browse the repository at this point in the history
Co-authored-by: Hans Trompert <[email protected]>
  • Loading branch information
dependabot[bot] and hanstrompert authored Jun 13, 2024
1 parent 3e6bc86 commit 13dbe0e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pynacl==1.5.0
# via paramiko
python-dotenv==1.0.1
# via pydantic-settings
python-statemachine==1.0.3
python-statemachine==2.3.1
# via supa (setup.cfg)
pytz==2024.1
# via
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
colorama ~= 0.4.3
click ~= 8.0
pydantic-settings ~= 2.3.1
python-statemachine ~= 1.0.3
python-statemachine ~= 2.3.1
sqlalchemy ~= 2.0.30
apscheduler ~= 3.10.4
tabulate ~= 0.9.0
Expand Down
26 changes: 7 additions & 19 deletions src/supa/connection/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,8 @@
logger = structlog.get_logger(__name__)


class SuPAStateMachine:
"""Add logging capabilities to StateMachine.
The python-statemachine version 0.x allowed class Statemachine to be used as a base class like this:
class SuPAStateMachine(StateMachine)
But version 1.x wil trigger a "statemachine.exceptions.InvalidDefinition: There are no states." exception
when there are no states defined in the StateMachine derived class, this is why, for now,
we use multiple inheritance to override the methods, like in:
class ReservationStateMachine(SuPAStateMachine, StateMachine)
"""
class SuPAStateMachine(StateMachine):
"""Add logging capabilities to StateMachine."""

log: BoundLogger

Expand All @@ -68,11 +57,10 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
def on_enter_state(self, state: State) -> None:
"""Statemachine will call this function on every state transition."""
if isinstance(state, State):
connection_id = self.model.connection_id # type: ignore[attr-defined]
self.log.info("State transition", to_state=state.id, connection_id=str(connection_id))
self.log.info("State transition", to_state=state.id, connection_id=str(self.model.connection_id))


class ReservationStateMachine(SuPAStateMachine, StateMachine):
class ReservationStateMachine(SuPAStateMachine):
"""Reservation State Machine.
.. image:: /images/ReservationStateMachine.png
Expand All @@ -99,7 +87,7 @@ class ReservationStateMachine(SuPAStateMachine, StateMachine):
)


class ProvisionStateMachine(SuPAStateMachine, StateMachine):
class ProvisionStateMachine(SuPAStateMachine):
"""Provision State Machine.
.. image:: /images/ProvisionStateMachine.png
Expand All @@ -116,7 +104,7 @@ class ProvisionStateMachine(SuPAStateMachine, StateMachine):
release_confirmed = Releasing.to(Released)


class LifecycleStateMachine(SuPAStateMachine, StateMachine):
class LifecycleStateMachine(SuPAStateMachine):
"""Lifecycle State Machine.
.. image:: /images/LifecycleStateMachine.png
Expand All @@ -134,7 +122,7 @@ class LifecycleStateMachine(SuPAStateMachine, StateMachine):
terminate_confirmed = Terminating.to(Terminated)


class DataPlaneStateMachine(SuPAStateMachine, StateMachine):
class DataPlaneStateMachine(SuPAStateMachine):
"""DataPlane State Machine.
.. image:: /images/DataPlaneStateMachine.png
Expand Down
4 changes: 2 additions & 2 deletions src/supa/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ def correlation_id(self) -> uuid.UUID:
reservation_state = mapped_column(
Enum(*[s.value for s in ReservationStateMachine.states]),
nullable=False,
default=ReservationStateMachine.ReserveStart.value, # type: ignore[has-type]
default=ReservationStateMachine.ReserveStart.value,
)
provision_state = mapped_column(Enum(*[s.value for s in ProvisionStateMachine.states]))
lifecycle_state = mapped_column(
Enum(*[s.value for s in LifecycleStateMachine.states]),
nullable=False,
default=LifecycleStateMachine.Created.value, # type: ignore[has-type]
default=LifecycleStateMachine.Created.value,
)
data_plane_state = mapped_column(Enum(*[s.value for s in DataPlaneStateMachine.states]))
# need this because the reservation state machine is missing a state
Expand Down

0 comments on commit 13dbe0e

Please sign in to comment.