No function clause matching in Ash.Actions.Helpers.set_context/2

I was using Ash_Authentication and switched to Guardian.
So when I ran the method, I found the following error.
I think it’s an error in the part where the router puts the context, but I don’t know why.

resource.ex

update :increment_dental_lab_post_view_count do
      require_atomic? false

      accept []
      change atomic_update(:count_of_view, expr(count_of_view + 1))
    end

router.ex

...
pipeline :api_with_auth do
    plug :accepts, ["json"]
    plug DentallogWeb.Auth.JwtPipeline
    plug :_set_actor
    plug AshGraphql.Plug
  end


...

defp _set_actor(conn, _opts) do
    case DentallogWeb.Auth.Guardian.Plug.current_resource(conn) do
      {:ok, user} -> set_actor(conn, user)
      nil -> conn
    end
  end

jwt_pipeline.ex

defmodule DentallogWeb.Auth.JwtPipeline do
  use Guardian.Plug.Pipeline,
    otp_app: :dentallog,
    module: DentallogWeb.Auth.Guardian,
    error_handler: DentallogWeb.Errors.GuardianErrorHandler

  plug Guardian.Plug.VerifySession
  plug Guardian.Plug.VerifyHeader
  plug Guardian.Plug.EnsureAuthenticated
  plug Guardian.Plug.LoadResource
end

[error] e7be1636-352e-42cd-b754-4058e247c7fa: Exception raised while resolving query.

** (FunctionClauseError) no function clause matching in Ash.Actions.Helpers.set_context/2

(ash 3.0.16) lib/ash/actions/helpers.ex:55: Ash.Actions.Helpers.set_context({:error, "Cannot perform a changeset with after action hooks atomically"}, %{})
(ash 3.0.16) lib/ash/actions/helpers.ex:66: Ash.Actions.Helpers.set_context_and_get_opts/3
(ash 3.0.16) lib/ash/actions/update/bulk.ex:151: Ash.Actions.Update.Bulk.run/6
(ash_graphql 1.2.0) lib/graphql/resolver.ex:1236: AshGraphql.Graphql.Resolver.mutate/2
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:189: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:174: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:145: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:67: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
(absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
(absinthe 1.7.7) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
(absinthe_plug 1.5.8) lib/absinthe/plug.ex:536: Absinthe.Plug.run_query/4
(absinthe_plug 1.5.8) lib/absinthe/plug.ex:290: Absinthe.Plug.call/2
(phoenix 1.7.14) lib/phoenix/router/route.ex:42: Phoenix.Router.Route.call/2
(phoenix 1.7.14) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
(dentallog 0.1.0) lib/dentallog_web/endpoint.ex:1: DentallogWeb.Endpoint.plug_builder_call/2
(dentallog 0.1.0) deps/plug/lib/plug/debugger.ex:136: DentallogWeb.Endpoint."call (overridable 3)"/2
(dentallog 0.1.0) lib/dentallog_web/endpoint.ex:1: DentallogWeb.Endpoint.call/2
(phoenix 1.7.14) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4

That particular constraint has been removed, so try the latest version of ash,ash_graphql etc. :slight_smile:

Thank you but I got another error

[error] 2fc59a64-dcfc-4354-b8af-02d2056c3be4: Exception raised while resolving query.

** (KeyError) key :changed? not found in: %{
  private: %{
    authorize?: true,
    actor: #Dentallog.Accounts.User<
      paper_trail_versions: #Ash.NotLoaded<:relationship, field: :paper_trail_versions>,
      __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
      id: "39f273d4-5fee-4f7c-aca8-6c3087c606c3",
      email: #Ash.CiString<"sh95119@gmail.com">,
      nickname: "example4",
      profile_image_url: nil,
      is_confirmed: false,
      is_doctor_confirm: false,
      created_at: ~U[2024-04-30 03:55:52.639725Z],
      updated_at: ~U[2024-04-30 03:55:52.639725Z],
      archived_at: nil,
      aggregates: %{},
      calculations: %{},
      ...
    >,
    tenant: nil,
    pre_flight_authorization?: false
  }
}

    (ash_paper_trail 0.1.4) lib/resource/changes/create_new_version.ex:33: anonymous fn/2 in AshPaperTrail.Resource.Changes.CreateNewVersion.create_new_version/1
    (ash 3.2.6) lib/ash/changeset/changeset.ex:3554: anonymous fn/2 in Ash.Changeset.run_after_actions/3
    (elixir 1.16.1) lib/enum.ex:4842: Enumerable.List.reduce/3
    (elixir 1.16.1) lib/enum.ex:2582: Enum.reduce_while/3
    (ash 3.2.6) lib/ash/actions/update/bulk.ex:551: anonymous fn/4 in Ash.Actions.Update.Bulk.do_atomic_update/5
    (elixir 1.16.1) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ash 3.2.6) lib/ash/actions/update/bulk.ex:548: Ash.Actions.Update.Bulk.do_atomic_update/5
    (ecto_sql 3.11.3) lib/ecto/adapters/sql.ex:1358: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
    (db_connection 2.7.0) lib/db_connection.ex:1756: DBConnection.run_transaction/4
    (ash 3.2.6) lib/ash/actions/update/bulk.ex:243: Ash.Actions.Update.Bulk.run/6
    (ash_graphql 1.2.1) lib/graphql/resolver.ex:1236: AshGraphql.Graphql.Resolver.mutate/2
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:234: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:189: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:174: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:145: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:67: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
    (absinthe 1.7.7) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
    (absinthe 1.7.7) lib/absinthe/pipeline.ex:408: Absinthe.Pipeline.run_phase/3
    (absinthe_plug 1.5.8) lib/absinthe/plug.ex:536: Absinthe.Plug.run_query/4

I’ve made a patch to ash main to resolve that issue. You can try it out if you like. Please open an issue if the issue persists.

I’m sorry, I tried to do that, but I ran into a dependency issue. Do you know how to fix the dependency issue?

mix.exs

 defp deps do
    [
      {:ash, git: "https://github.com/ash-project/ash.git", branch: "main"},
      {:ash_postgres, "~> 2.0.12"},
      {:ash_phoenix, "~> 2.0.4"},
...

{:ash, git: "https://github.com/ash-project/ash.git", branch: "main", override: true},

It works fine. As always, thank you for your kind and quick response.