albin
Handle_event updating the wrong record
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
Marked As Solved
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.
1
Popular in Questions
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
I would like to know what is the best IDE for elixir development?
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









