Skip to content

Checking if conditions are valid before going through the transition #520

@wipoulou

Description

@wipoulou

Thank you for this library, it's been very helpful!
However I've been trying to check before going through a transition to see if it was possible to do it, and I couldn't figure it out.

I've been looking through the documentation, the source code (although not 100% of it), the issues on GitHub, stack overflow, and asked an LLM how to do it but I couldn't figure it out, so excuse me if I simply missed it.

Again, I'm looking to check wether a transition is possible before I attempt to do it.
I'm aware that if it is not possible, it will throw an error, but I can't rely on this behavior as if there is no error then the transition actions are triggered (which make database modifications, so not easy to rollback).

The reason why I'm trying to do that, is that I have a Django application that leverages this library to transition on object states, and from a given state, I can go to multiple other states. There should only be one state possible at any given time, but I don't want to trigger it just yet, I just want to show a button in the UI for which one it is.

The way I'm doing it right now is a bit idiotic, I only use the "cond" parameter, with only AND and NOR boolean algebra conditions, and I made a sort of (very simple) custom AST parser to call the conditions and check that they all evaluate to True.

Did I miss something? Is what I'm doing an anti-pattern? I'd be fine with a cleaner workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions