question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get all available transitions for given state?

See original GitHub issue

I am using the following piece of code:

from transitions import Machine
import random

class MyMachine:
    states = ['in_danger', 'victorious', 'defeated', 'escaped']

    def __init__(self):
        self.machine = Machine(
            model=self, states=MyMachine.states, initial='in_danger'
        )
        self.machine.add_transition('run', 'in_danger', 'escaped')
        self.machine.add_transition(
            'fight', 'in_danger', 'victorious', conditions=['made_it']
        )
        self.machine.add_transition('fight', 'in_danger', 'defeated')
        self.machine.add_transition('back', '*', 'in_danger')

    def made_it(self):
        return random.random() < 0.25

mm = MyMachine()

I’d like to have a list of available actions (triggers?) for each state (or just the state the machine is currently in). For given example it would look like this:

in_danger: run, fight
victorious: back
defeated: back
escaped: back

I know I can initialize the state machine with the list of states and transitions, so if I do it that way I will already have available transitions for all states. But is there a way to access this information from the machine itself?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pfertykcommented, Feb 27, 2017

That is exactly what I was looking for 😉 Thanks for a quick response and forgive me for not reading the README file closely enough.

The issue can be closed.

1reaction
aleneumcommented, Feb 27, 2017

Automatic transitions for all states

In addition to any transitions added explicitly, a to_«state»() method is created automatically whenever a state is added to a Machine instance. … If you desire, you can disable this behavior by setting auto_transitions=False in the Machine initializer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Listing All JIRA Transitions via API - Stack Overflow
You can list the transitions of a given ticket via this endpoint: /rest/api/2/issue/${issueIdOrKey}/transitions. For a more in depth explanation take a look ...
Read more >
Is there anyway i can get all the transitions of a...
I want to change the transition of issue using 'Rest API' for my automation release tool. Is there any way i can get...
Read more >
Get Transitions with the Jira API - Pipedream
Configure the Get Transitions action. Connect your Jira account; Select a Issue id or key; Optional- Configure Transition ID · Select a trigger...
Read more >
ScriptRunner for Jira - Get workflow details like steps and ...
After getting the list of workflows you most probably want to do more like get the list of steps and all the possible...
Read more >
JIRA Tutorial #19 - JIRA Workflow Transitions in Detail
Get all my courses for USD 5.99/Month - https://bit.ly/ all -courses-subscription FREE Training's at https://training.rcvacademy.com ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found