After upgrading to the latest Ash/AshAuthentication version (I’m not sure which one exactly triggered the issue since it was not me who did it), my register_with_password
action stopped working when creating a changeset.
Here is my action:
create :register_with_password do
primary? true
alias AshAuthentication.{GenerateTokenChange, Strategy.Password}
accept [:email, :first_name, :surname, :phone_number, :allow_marketing_emails?]
argument :password, :string, allow_nil?: false, sensitive?: true
argument :password_confirmation, :string, allow_nil?: false, sensitive?: true
argument :referrer_code, :uuid, allow_nil?: true
metadata :token, :string
validate Password.PasswordConfirmationValidation
change GenerateTokenChange
change Password.HashPasswordChange
end
In my changes
block, I have the following:
changes do
alias Marketplace.Accounts.User.Actions
change Actions.PasswordResetWithPassword.Changes.RemoveAllTokens,
where: [action_is(:password_reset_with_password)]
end
When I try to create a changeset using this action:
Accounts.User
|> Ash.Changeset.new()
|> Ash.Changeset.for_create(:register_with_password, super_user_args)
I will get the following error:
** (FunctionClauseError) no function clause matching in Keyword.drop/2
The following arguments were given to Keyword.drop/2:
# 1
%{action: :password_reset_with_password}
# 2
[:field, :message, :path]
Attempted function clauses (showing 1 out of 1):
def drop(keywords, keys) when is_list(keywords) and is_list(keys)
(elixir 1.16.0) lib/keyword.ex:1266: Keyword.drop/2
(elixir 1.16.0) lib/map.ex:676: Map.update/4
(ash 2.18.1) lib/ash/resource/validation/action_is.ex:14: Ash.Resource.Validation.ActionIs.validate/2
(ash 2.18.1) lib/ash/changeset/changeset.ex:1708: anonymous fn/5 in Ash.Changeset.run_action_changes/6
(elixir 1.16.0) lib/enum.ex:4202: Enum.predicate_list/3
(ash 2.18.1) lib/ash/changeset/changeset.ex:1692: anonymous fn/6 in Ash.Changeset.run_action_changes/6
(elixir 1.16.0) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash 2.18.1) lib/ash/changeset/changeset.ex:1279: Ash.Changeset.do_for_action/4
priv/repo/seeds.exs:34: (file)
(elixir 1.16.0) lib/code.ex:1485: Code.require_file/2
(mix 1.16.0) lib/mix/tasks/run.ex:146: Mix.Tasks.Run.run/5
(mix 1.16.0) lib/mix/tasks/run.ex:85: Mix.Tasks.Run.run/1
(mix 1.16.0) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
(mix 1.16.0) lib/mix/task.ex:544: Mix.Task.run_alias/6
(mix 1.16.0) lib/mix/cli.ex:96: Mix.CLI.run_task/2
/var/home/sezdocs/.asdf/installs/elixir/1.16.0/bin/mix:2: (file)
(elixir 1.16.0) lib/code.ex:1485: Code.require_file/2
Looking into it, when running the run_action_changes/6
function from Ash.Changeset
, ash will try to validate the RemoveAllTokens
change:
%Ash.Resource.Change{
change: {Marketplace.Accounts.User.Actions.PasswordResetWithPassword.Changes.RemoveAllTokens,
[]},
on: [:create, :update],
only_when_valid?: false,
description: nil,
always_atomic?: false,
where: [
{Ash.Resource.Validation.ActionIs,
[action: :password_reset_with_password]}
]
}
Using the Ash.Resource.Validation.ActionIs
and for some reason it will give that error.