Ash FrameworkAF
Ash Frameworkโ€ข4mo agoโ€ข
3 replies
Shahryar

Attempted to update stale record error update record in a loop

I think it is from ecto and i miss something, i do not want to use Ash generator here! so with a sleep it returns error
** (Ash.Error.Invalid)
Bread Crumbs:
  > Error returned from: MishkaCms.Runtime.Layout.update

Invalid Error

* Attempted to update stale record of MishkaCms.Runtime.Layout with filter: site_id == "77fb97f0-2b9f-4831-aadd-b6a956ad0ead


Simple Code:

layout_id = layout.id

Enum.each(1..25, fn item ->
  fresh_layout = Ash.get!(MishkaCms.Runtime.Layout, layout_id, action: :get_any, authorize?: false)

  fresh_layout
  |> Ash.Changeset.for_update(:update, %{
    description: "Simple main layout with navigation V#{item}"
  })
  |> Ash.update!(tenant: site.id, actor: none_user, authorize?: false, atomic_upgrade?: false)

  Process.sleep(300)
end)


What am i missing? every time i get record again ๐Ÿค” thanks
Solution
I wrapped it inside, i think it fixed my code ๐Ÿง‘โ€๐Ÿ’ป
Ash.DataLayer.transaction(MishkaCms.Runtime.Layout, fn ->
....
end)
Was this page helpful?