Skip to content

Commit 8054786

Browse files
authored
Fix domain model bool check (#533)
1 parent b0367f0 commit 8054786

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

statemachine/statemachine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
allow_event_without_transition: bool = False,
7676
listeners: "List[object] | None" = None,
7777
):
78-
self.model = model if model else Model()
78+
self.model = model if model is not None else Model()
7979
self.state_field = state_field
8080
self.start_value = start_value
8181
self.allow_event_without_transition = allow_event_without_transition

tests/test_statemachine.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,18 @@ class TrapStateMachine(StateMachine):
488488
start = started.to(producing)
489489
close = started.to(closed)
490490
add_job = producing.to.itself(internal=True)
491+
492+
493+
def test_model_with_custom_bool_is_not_replaced(campaign_machine):
494+
class FalseyModel(MyModel):
495+
def __bool__(self):
496+
return False
497+
498+
model = FalseyModel()
499+
machine = campaign_machine(model)
500+
501+
assert machine.model is model
502+
assert model.state == "draft"
503+
504+
machine.produce()
505+
assert model.state == "producing"

0 commit comments

Comments
 (0)