`after_action` hook does not trigger with atomic changes

I have observed that after_action hook silently gets ignored when a change is atomic but when I set require_atomic? to false it triggers.

I could not find anything in the docs that explains the rationale behind this behavour. Does anyone know why? before_action seems to work with atomic changes

Is your ash package up to date?

1 Like

I have updated Ash package from 3.4.63 to 3.5.9 but the issue still remains.

Action

    update :complete do
      accept []
      # require_atomic? false <--- Uncommenting this line works.
      change HR.Performances.GoalMilestone.Changes.Complete
    end

Change

defmodule HR.Performances.GoalMilestone.Changes.Complete do
  use Ash.Resource.Change
  require Ash.Query

  def change(changeset, _opts, _context) do
    changeset
    |> Ash.Changeset.after_action(&maybe_complete_goal/2)
    |> Ash.Changeset.change_attribute(:status, :completed)
  end

  def atomic(changeset, _opts, _context), do: {:ok, changeset}

  def maybe_complete_goal(_changeset, milestone) do
    # This code is not being reached.
    dbg("Checking for incomplete milestones")
    milestone
  end
end

Your atomic callback is bypassing the change/3 behavior. If you want it to do the “normal” behavior on atomic execution, then you need

  def atomic(changeset, opts, context), do: {:ok, change(changeset, opts, context)}

Thank you. It worked.

1 Like