jan-mb-me
Hi,
I stumbled over this snippet of a query generated by an update action:
SET “updated_at” = (CASE WHEN $1::timestamp != r0.“last_query_at”::timestamp THEN $2::timestamp ELSE r0.“updated_at”::timestamp END)
The attribute is defined as below, i.e. the column is nullable:
attribute :last_query_at, :utc_datetime_usec do
public? true
filterable? true
end
When the record/row has NULL in field/column last_query_at and I pass a date-time value for last_query_at to the update action, the operator != prevents the condition to resolve to TRUE, hence updated_at is not changed although the row is changed to a new value for last_query_at (not shown in the snippet above).
That default behavior caught me by surprise.
From what I found so far, I‘d have to use this in the update action to skip the “only update if changed“ optimization:
change atomic_update(:last_query_at, expr(^arg(:last_query_at)))
Am I missing something to make the update of updated_at work without ?atomic_update
I am using ash 3.19.3 and ash-postgres 2.6.32.
Update: Using atomic_update leads to the same snippet being generated.
Trending in Questions
Other Trending Topics
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
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 9 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jan-mb-me
Hello @zachdaniel, Upgrading to ash 3.23.0+ and also upgrading ash_sql worked and my workaround became obsolete.
Thank you very much!
zachdaniel
Please also update ash_sql
jan-mb-me
I couldn’t upgrade past 3.22.2. Starting with 3.23.0 (also with 3.23.1) an embedded resource (the only one so far) doesn’t work anymore:
I have to postpone further investigation until Tuesday.
In case it matters: I am not using ash_json_api.
zachdaniel
Release is available: 3.23.0
jan-mb-me
Wow, that was quick! Thank you, @zachdaniel.
Can’t test
mainhere at work but the fix looks exactly like what was missing:https://github.com/ash-project/ash/commit/05814f9339a47fb91286099c6ebc76d19873c794
zachdaniel
Hey @jan-mb-me thank you for the find! This is fixed in the latest
mainofashand will be included in the next release.jan-mb-me
Yes, I’ll create a ticket, but probably not until Friday or the weekend.
zachdaniel
Definitely a problem. Can you share more about the action definition? Ideally sharing a reproduction and opening an issue containing that. I can fix
jan-mb-me
My workaround is to explicitly change the attribute
updated_atin the action: