albin

albin

I have this code snippet from the getting started guide for ash_phoenix:
Repo GitHub - albinkc/my_ash_phoenix_app_tut · GitHub

def handle_event("update_post", %{"form" => form_params}, socket) do
    case AshPhoenix.Form.submit(socket.assigns.update_form, params: form_params) do
      {:ok, _post} ->
        posts = Blog.list_posts!()

        {:noreply, assign(socket, posts: posts, post_selector: post_selector(posts))}

      {:error, update_form} ->
        {:noreply, assign(socket, update_form: update_form)}
    end
  end
[debug] HANDLE EVENT "update_post" in MyAshPhoenixAppWeb.PostsLive
  Parameters: %{"form" => %{"content" => "uh", "post_id" => "ae34b684-7308-42eb-8ea1-f0455fcb66a6"}}
[debug] QUERY OK source="posts" db=2.3ms idle=1555.3ms
UPDATE "posts" AS p0 SET "content" = $1::text::text WHERE (p0."id"::uuid = $2::uuid) RETURNING p0."id", p0."title", p0."content" ["uh", "f38c0f31-42f8-4bce-847c-ec3dd3593d6b"]
↳ AshPostgres.DataLayer.update_query/4, at: lib/data_layer.ex:1380
[debug] QUERY OK source="posts" db=0.6ms idle=1561.4ms
SELECT p0."id", p0."title", p0."content" FROM "posts" AS p0 []
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:767
[debug] Replied in 12ms

notice the uuids are different in the form_params vs the postgres statement. Furthermore, if I delete all but one record from the db table and then try the update, I get this cryptic warning. No db update occurs in this case.

[debug] HANDLE EVENT "update_post" in MyAshPhoenixAppWeb.PostsLive
  Parameters: %{"form" => %{"content" => "hehe", "post_id" => "43c61b5a-18d4-4c74-9063-2c90fee59724"}}
[debug] QUERY OK source="posts" db=1.0ms idle=1857.1ms
UPDATE "posts" AS p0 SET "content" = $1::text::text WHERE (p0."id"::uuid = $2::uuid) RETURNING p0."id", p0."title", p0."content" ["hehe", "f38c0f31-42f8-4bce-847c-ec3dd3593d6b"]
↳ AshPostgres.DataLayer.update_query/4, at: lib/data_layer.ex:1380
warning: the following fields are unknown when raising Ash.Error.Changes.StaleRecord: [filters: %{id: "f38c0f31-42f8-4bce-847c-ec3dd3593d6b"}]. Please make sure to only give known fields when raising or redefine Ash.Error.Changes.StaleRecord.exception/1 to discard unknown fields. Future Elixir versions will raise on unknown fields given to raise/2
  (ash 3.3.3) lib/ash/error/changes/stale_record.ex:5: Ash.Error.Changes.StaleRecord."exception (overridable 1)"/1
  (ash 3.3.3) lib/ash/error/changes/stale_record.ex:5: Ash.Error.Changes.StaleRecord.exception/1
  (ash 3.3.3) lib/ash/actions/update/update.ex:183: Ash.Actions.Update.run/4
  (ash 3.3.3) lib/ash.ex:2502: Ash.update/3
  (ash_phoenix 2.1.1) lib/ash_phoenix/form/form.ex:2043: AshPhoenix.Form.with_changeset/2
  (ash_phoenix 2.1.1) lib/ash_phoenix/form/form.ex:1861: AshPhoenix.Form.submit/2
  (ash_phoenix 2.1.1) lib/ash_phoenix/form/form.ex:1790: AshPhoenix.Form.submit/2
  (my_ash_phoenix_app 0.1.0) lib/my_ash_phoenix_app_web/posts_live.ex:79: MyAshPhoenixAppWeb.PostsLive.handle_event/3
  (phoenix_live_view 1.0.0-rc.6) lib/phoenix_live_view/channel.ex:508: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3
  (telemetry 1.2.1) /Users/albin/projects/ash_builder/my_ash_phoenix_app/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
  (phoenix_live_view 1.0.0-rc.6) lib/phoenix_live_view/channel.ex:260: Phoenix.LiveView.Channel.handle_info/2
  (stdlib 6.0) gen_server.erl:2173: :gen_server.try_handle_info/3
  (stdlib 6.0) gen_server.erl:2261: :gen_server.handle_msg/6
  (stdlib 6.0) proc_lib.erl:340: :proc_lib.wake_up/3

[warning] Unhandled error in form submission for MyAshPhoenixApp.Blog.Post.update

This error was unhandled because Ash.Error.Changes.StaleRecord does not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Changes.StaleRecord) Attempted to update stale record of MyAshPhoenixApp.Blog.Post

[debug] Replied in 4ms

how can I make this work? TIA

Showing Posts 1 to 3

zachdaniel

zachdaniel

Creator of Ash

The record to be updated does not come from form params but from what is passed in to create the form. What are you passing into AshPhoenix.Form.for_update?

zachdaniel

zachdaniel

Creator of Ash

Looks like you’re always updating the first post in the list regardless of params: my_ash_phoenix_app_tut/lib/my_ash_phoenix_app_web/posts_live.ex at 028ad59eb91989d16d81cf758a76f858db86f2b6 · albinkc/my_ash_phoenix_app_tut · GitHub

To change what you’re updating, you’ll need to replace the form with a new form.

albin

albin OP

Thank you for taking the time! That should work.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews