Expected action of type :update, but :destroy is of type :destroy

Dear community,

I’ve set up AshAdmin and upon applying the delete action on my resource I get the following error:

** (ArgumentError) Expected action of type :update, but :destroy is of type :destroy

I’ve done a thorough search of the forum and elsewhere (not Discord though). Look, I’m sure I’m “holding it wrong” but I really haven’t been able to find this issue documented, let alone any solution to it.

Does this make sense to anyone?

Any help would truly be appreciated.

Output

[debug] QUERY OK source="my_resource" db=0.2ms idle=1419.1ms
SELECT a0."id", a0."resource_type", a0."status" FROM "my_resource" AS a0 WHERE (a0."id"::uuid = $1::uuid) ["d6d0580a-07d0-428b-a881-e5979bf80ee4"]
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:684
[info] Sent 500 in 77ms
[error] GenServer #PID<0.1135.0> terminating
** (ArgumentError) Expected action of type :update, but :destroy is of type :destroy
    (ash_phoenix 1.2.26) lib/ash_phoenix/form/form.ex:855: AshPhoenix.Form.require_action!/3
    (ash_phoenix 1.2.26) lib/ash_phoenix/form/form.ex:650: AshPhoenix.Form.for_destroy/3
    (ash_admin 0.10.2) lib/ash_admin/components/resource/form.ex:1627: AshAdmin.Components.Resource.Form.assign_form/1
    (ash_admin 0.10.2) lib/ash_admin/components/resource/form.ex:37: AshAdmin.Components.Resource.Form.update/2
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/utils.ex:498: Phoenix.LiveView.Utils.maybe_call_update!/3
    (elixir 1.16.0) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:681: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
    (telemetry 1.2.1) /Users/myusername/Developer/my_app/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:676: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
    (stdlib 5.1.1) maps.erl:416: :maps.fold_1/4
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:635: Phoenix.LiveView.Diff.render_pending_components/6
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/static.ex:249: Phoenix.LiveView.Static.to_rendered_content_tag/4
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/static.ex:132: Phoenix.LiveView.Static.render/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
    (phoenix 1.7.11) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
    (my_app 0.1.0) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.plug_builder_call/2
    (my_app 0.1.0) deps/plug/lib/plug/debugger.ex:136: MyAppWeb.Endpoint."call (overridable 3)"/2
    (my_app 0.1.0) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.call/2
    (phoenix 1.7.11) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
Last message: {:continue, :handle_connection}
State: {%ThousandIsland.Socket{socket: #Port<0.65>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, silent_terminate_on_error: false, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.56314858.2486435844.140628>, start_time: -576460524402657788, start_metadata: %{remote_port: 50519, remote_address: {127, 0, 0, 1}, telemetry_span_context: #Reference<0.56314858.2486435844.140628>, parent_telemetry_span_context: #Reference<0.56314858.2486435844.139854>}}}, %{opts: %{websocket: [], http_1: [], http_2: []}, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {MyAppWeb.Endpoint, []}}, handler_module: Bandit.InitialHandler, http_1_enabled: true, http_2_enabled: true, websocket_enabled: true}}

Dependencies

  ash 2.18.2
  ash_admin 0.10.2
  ash_authentication 3.12.2
  ash_authentication_phoenix 1.9.0
  ash_phoenix 1.2.26
  ash_postgres 1.4.0
  assent 0.2.9
  bandit 1.2.0
  bcrypt_elixir 3.1.0
  castore 1.0.5
  comeonin 5.4.0
  comparable 1.0.0
  db_connection 2.6.0
  decimal 2.1.1
  dns_cluster 0.1.3
  earmark 1.4.46
  ecto 3.11.1
  ecto_sql 3.11.1
  elixir_make 0.7.8
  esbuild 0.8.1
  ets 0.9.0
  expo 0.5.1
  file_system 0.2.10
  finch 0.17.0
  floki 0.35.3
  gettext 0.24.0
  hpax 0.1.2
  jason 1.4.1
  joken 2.6.0
  jose 1.11.6
  mime 2.0.5
  mint 1.5.2
  nimble_options 1.1.0
  nimble_pool 1.0.0
  phoenix 1.7.11
  phoenix_ecto 4.4.3
  phoenix_html 3.3.3
  phoenix_live_dashboard 0.8.3
  phoenix_live_reload 1.4.1
  phoenix_live_view 0.20.4
  phoenix_pubsub 2.1.3
  phoenix_template 1.0.4
  phoenix_view 2.0.3
  picosat_elixir 0.2.3
  plug 1.15.3
  plug_crypto 2.0.0
  postgrex 0.17.4
  slugify 1.3.1
  sourceror 0.14.1
  spark 1.1.54
  stream_data 0.6.0
  swoosh 1.15.1
  tails 0.1.8
  tailwind 0.2.2
  telemetry 1.2.1
  telemetry_metrics 0.6.2
  telemetry_poller 1.0.0
  thousand_island 1.3.2
  typable 0.3.0
  websock 0.5.3
  websock_adapter 0.5.5

Resource

defmodule MyApp.MyApi.MyResource do
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshAdmin.Resource]

  attributes do
    uuid_primary_key :id

    attribute :resource_type, :atom do
      constraints one_of: [:a, :b, :c]
    end

    attribute :status, :atom do
      constraints one_of: [:created, :processing, :succeeded, :failed]

      default :created
    end
  end

  actions do
    defaults [:create, :read, :update, :destroy]
  end

  postgres do
    table "my_resource"
    repo MyApp.Repo
  end
end

Ash API

defmodule MyApp.MyApi do
  use Ash.Api,
    extensions: [AshAdmin.Api]

  admin do
    show? true
  end

  resources do
    resource MyApp.MyApi.MyResource
  end
end

Config

# Ash Framework
config :my_app,
  ash_apis: [MyApp.MyOtherApi, MyApp.MyApi]

This looks like a bug in ash admin internals actually :sob: don’t think you’re doing anything wrong at all. I’ll take a look later today.

1 Like

Phew, then it’s not just me (perhaps) :face_exhaling:

Thanks for taking the time to comment. I’ll send you an invite as a collaborator on a repo that reproduces the issue.

Thanks for an amazing job on Ash!

1 Like

Thank you for the reproduction :slight_smile: I’ve pushed a fix up, and published new versions of ash_admin and ash_phoenix. You’ll also need to update phoenix_html to ~> 4.0 to use the latest versions of those packages.

1 Like

Wow – thank you Zach!

1 Like