MikaelFangel

MikaelFangel

Getting attempted to transition to an unknown state using forms auto

I have an Ash state machine defined for a resource, which I want to use to ensure that users change the status to one of the allowed in the business process model. The state machine works fine when using it with my create action. However, when I try to use it with my update action, it gives me an error in the debug messages. The error message doesn’t prohibit me from using the form, and when updating the form it actually works like it’s supposed to. I’m not sure if I’m missing something or if it’s a small bug? My question is: How do I fix this error message without allowing nil as an extra_state? The reason I want to avoid the extra_state is because it violates the attribute constraint.

The state machine definition:

  @valid_states [:state_a, :state_b, :state_c, :state_d]
  @closed_states [:state_c, :state_d]

  state_machine do
    initial_states(@valid_states)
    default_initial_state(:state_a)
    state_attribute(:status)

    transitions do
      transition(:*, from: :state_a, to: @valid_states)
      transition(:*, from: :state_b, to: @valid_states)
      transition(:*, from: :state_c, to: @closed_states)
      transition(:*, from: :state_d, to: @closed_states)
    end

The attribute in question

    attribute :status, :atom do
      constraints one_of: @valid_states
      default :state_a
      allow_nil? false
      public? true
    end

How I create the form:

    form =
      case
      |> Form.for_update(:update, forms: [auto?: true])
      |> to_form()

The error message:

[error] Attempted to transition to an unknown state.

This usually means that one of the following is true:

* You have a missing transition definition in your state machine

  To remediate this, add a transition.

* You are using `:*` to include a state that appears nowhere in the state machine definition

  To remediate this, add the `extra_states` option and include the state nil

First Post!

zachdaniel

zachdaniel

Creator of Ash

Is the warning just that? Or does it say more at the top like “unknown error …”?

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31307 143
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement