get_and_lock_for_update missing data
Hello!
I have an action that does a
get_and_lock_for_update
, then does an anonymous function change. It does this in order to do an array append into an {:array, :map} field.
3 Replies
When running it, I see the queries I would expect, first a
SELECT FOR UPDATE
, then an update, and finall a commit
When I run this sequentially, only the last inserted element is actually inserted. This is because it seems that the story inside the Changeset is never refreshed and it still has the original items. I'd expect that get_and_lock_for_update
would refetch (with the SELECT FOR UPDATE
) and then apply the changes. However it seems that that is not what it's doing?🤔 I'm not sure if it replaces the data with the fetched data, but it would make sense for it to do that.
I'd check the source for that change and if its not feel free to open an issue/PR. To make it not a breaking change, we'd likely need to add
get_and_lock_for_update(..., replace?: true)
hmm, if I'm reading this right it should be updating data to the latest:
https://github.com/ash-project/ash/blob/5d9456196e960b7884384b4fa53f98d8f0f17c5a/lib/ash/resource/change/get_and_lock_for_update.ex#L23-L24
I wonder what's going on, will try to debug later.
GitHub
ash/lib/ash/resource/change/get_and_lock_for_update.ex at 5d9456196...
A declarative, extensible framework for building Elixir applications. - ash-project/ash