Ash FrameworkAF
Ash Framework2mo ago
5 replies
Anonymous

Ash.changeset.set_context not working as expected

Hello.
I am creating a changeset and I am trying to set the context in the following way.

with {:ok, record} <- Ash.get(resource, record_id, authorize?: false) do
      # Merge relationships into attributes as arguments for the action
      action_input =
        attributes
        |> MapUtils.atomize_keys()
        |> Map.merge(prepare_relationship_arguments(relationships))

      changeset =
        record
        |> Ash.Changeset.for_update(action_name, action_input)
        |> Ash.Changeset.set_context(%{source: :mobile_changeset_apply})

      Ash.update(changeset, %{}, authorize?: false)
    end


But when this changeset is intercepted in Ash.Resource.Change.Change/3, I am not able to see this context anywhere.
Here is what I see for context passed in change function and in changeset.context.


changeset.context: %{private: %{authorize?: true}}

context: %Ash.Resource.Change.Context{
  actor: nil,
  tenant: nil,
  authorize?: true,
  tracer: nil,
  bulk?: false,
  source_context: %{private: %{authorize?: true}}
}


As per documentation, my set context should be available in changeset.context or source_context of Ash.Resource.Change.Context. Am I missing something? I would be really grateful for any guidance. Thank you.
Was this page helpful?