Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current_state check in ImplementationWrapper._pre_transition_checks #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions src/xworkflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def __str__(self):
def __repr__(self):
return '<%s: %r>' % (self.__class__.__name__, self.name)

def __eq__(self, other):
return self.name == other.name


class StateList(object):
"""A list of states."""
Expand Down Expand Up @@ -358,15 +361,17 @@ def __init__(self, instance, field_name, transition, workflow,

@property
def current_state(self):
return getattr(self.instance, self.field_name)
current_state = getattr(self.instance, self.field_name)
if isinstance(current_state, StateWrapper):
current_state = current_state.state
return current_state

def _pre_transition_checks(self):
"""Run the pre-transition checks."""
current_state = getattr(self.instance, self.field_name)
if current_state not in self.transition.source:
if self.current_state not in self.transition.source:
raise InvalidTransitionError(
"Transition '%s' isn't available from state '%s'." %
(self.transition.name, current_state.name))
(self.transition.name, self.current_state.name))

for check in self._filter_hooks(HOOK_CHECK):
if not check(self.instance):
Expand Down