AE
Ash Elixir•3y ago
Jason

(CaseClauseError) no case clause matching: #Ash.Changeset<api

This must be a very basic question but I'm getting the above error in running this code. add_user_timezone is defined in user.ex which is listed in MyApp.Accounts.Registry. What am I missing?
current_user
|> Ash.Changeset.for_update(:add_user_timezone, %{
browser_timezone: get_connect_params(socket)["timezone"]
})
|> Accounts.update!()
current_user
|> Ash.Changeset.for_update(:add_user_timezone, %{
browser_timezone: get_connect_params(socket)["timezone"]
})
|> Accounts.update!()
<Full error message>
** (CaseClauseError) no case clause matching: #Ash.Changeset<api: MyApp.Accounts, action_type: :update, action: :add_user_timezone, attributes: %{}, relationships: %{}, arguments: %{browser_timezone: nil}, errors: [], data: #MyApp.Accounts.User<...
first_name: nil, last_name: nil, user_photo_url: nil, user_timezone: nil, inserted_at: ~U[2023-02-16 05:40:59.959000Z], updated_at: ~U[2023-02-16 05:40:59.959000Z], aggregates: %{}, calculations: %{}, __order__: nil, ...>, context: %{actor: nil, authorize?: false}, valid?: true>
** (CaseClauseError) no case clause matching: #Ash.Changeset<api: MyApp.Accounts, action_type: :update, action: :add_user_timezone, attributes: %{}, relationships: %{}, arguments: %{browser_timezone: nil}, errors: [], data: #MyApp.Accounts.User<...
first_name: nil, last_name: nil, user_photo_url: nil, user_timezone: nil, inserted_at: ~U[2023-02-16 05:40:59.959000Z], updated_at: ~U[2023-02-16 05:40:59.959000Z], aggregates: %{}, calculations: %{}, __order__: nil, ...>, context: %{actor: nil, authorize?: false}, valid?: true>
<:add_user_timezone>
update :add_user_timezone do
accept [:user_timezone]

argument :browser_timezone, :string do
allow_nil? true
end

manual fn changeset, %{actor: actor} ->
case Ash.Changeset.get_argument(changeset, :browser_timezone) do
nil ->
changeset

browser_timezone ->
Ash.Changeset.force_change_attribute(changeset, :user_timezone, browser_timezone)
end
end
update :add_user_timezone do
accept [:user_timezone]

argument :browser_timezone, :string do
allow_nil? true
end

manual fn changeset, %{actor: actor} ->
case Ash.Changeset.get_argument(changeset, :browser_timezone) do
nil ->
changeset

browser_timezone ->
Ash.Changeset.force_change_attribute(changeset, :user_timezone, browser_timezone)
end
end
code_interface do
define_for MyApp.Accounts

define :add_user_timezone, args: [:brower_timezone]
end
code_interface do
define_for MyApp.Accounts

define :add_user_timezone, args: [:brower_timezone]
end
3 Replies
ZachDaniel
ZachDaniel•3y ago
in manual actions you don't return a changeset, you implement the action logic yourself and return the result I think you just want a change, there not manual although FWIW, you can just use this to the same effect:
change set_attribute(:user_timezone, arg(:browser_timezone))
change set_attribute(:user_timezone, arg(:browser_timezone))
Jason
JasonOP•3y ago
You are absolutely right! Thank you!!
ZachDaniel
ZachDaniel•3y ago
We should add validations for the return type of that function so that if you return the wrong value you get an explicit warning. If you have a minute to open a GH issue about it we could get it fixed 😄

Did you find this page helpful?