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
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
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
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
Thank you for taking the time! That should work.