jan-mb-me

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.

Showing Posts 9 to 1

jan-mb-me

jan-mb-me OP

Hello @zachdaniel, Upgrading to ash 3.23.0+ and also upgrading ash_sql worked and my workaround became obsolete.
Thank you very much!

zachdaniel

zachdaniel

Creator of Ash

Please also update ash_sql

jan-mb-me

jan-mb-me OP

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:

(Protocol.UndefinedError) protocol Jason.Encoder not implemented for Xyz.Recordings.TransferSettings (a struct), Jason.Encoder protocol must always be explicitly implemented.

I have to postpone further investigation until Tuesday.

In case it matters: I am not using ash_json_api.

zachdaniel

zachdaniel

Creator of Ash

Release is available: 3.23.0

jan-mb-me

jan-mb-me OP

Wow, that was quick! Thank you, @zachdaniel.

Can’t test main here at work but the fix looks exactly like what was missing:
https://github.com/ash-project/ash/commit/05814f9339a47fb91286099c6ebc76d19873c794

zachdaniel

zachdaniel

Creator of Ash

Hey @jan-mb-me thank you for the find! This is fixed in the latest main of ash and will be included in the next release.

:person_bowing:

jan-mb-me

jan-mb-me OP

Yes, I’ll create a ticket, but probably not until Friday or the weekend.

zachdaniel

zachdaniel

Creator of Ash

Definitely a problem. Can you share more about the action definition? Ideally sharing a reproduction and opening an issue containing that. I can fix :slight_smile:

jan-mb-me

jan-mb-me OP

My workaround is to explicitly change the attribute updated_at in the action:

change set_attribute(:updated_at, &DateTime.utc_now/0)
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
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
velrest
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
samoloth
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews