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

qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement