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

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

That is the full error message I get.

I have currently “solved” it by adding the nil state, which feels a bit hacky and probably isn’t the right solution.

Here is my current solution to suppress the error:

  state_machine do
    initial_states(@valid_states)
    default_initial_state(:state_a)
    state_attribute(:status)
    extra_states([nil])

    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

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

We are probably missing a special case for nil somewhere before logging an error. please open an issue and i’ll investigate further