Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion statemachine/statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
allow_event_without_transition: bool = False,
listeners: "List[object] | None" = None,
):
self.model = model if model else Model()
self.model = model if model is not None else Model()
self.state_field = state_field
self.start_value = start_value
self.allow_event_without_transition = allow_event_without_transition
Expand Down
15 changes: 15 additions & 0 deletions tests/test_statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,18 @@ class TrapStateMachine(StateMachine):
start = started.to(producing)
close = started.to(closed)
add_job = producing.to.itself(internal=True)


def test_model_with_custom_bool_is_not_replaced(campaign_machine):
class FalseyModel(MyModel):
def __bool__(self):
return False

model = FalseyModel()
machine = campaign_machine(model)

assert machine.model is model
assert model.state == "draft"

machine.produce()
assert model.state == "producing"
Loading