Resource actions - Transaction

Hi! I am currently working on some :create actions where I have SQLite3 as the datalayer. I have both before_action, manage_relatonship and after_action and I was expecting the whole create action to fail and the transaction to rollback if any of the changes failed. But this does not seem to be the case..? I have tried to set transaction? true manually but it still creates the tables entries even if manage_relationship fails and/or if any of the after_action fails. Looking at this chart: https://hexdocs.pm/ash/3.5.36/actions.html#complete-lifecycle-flow it seems that the transaction rollback only applies to the creation of the outer row, not related rows or after_action ? Is this a job that is better handled by AshReactor or something similar?
9 Replies
ZachDaniel
ZachDanielโ€ข2mo ago
Errors should result in rollbacks In after or before action hooks Would break a whole lot of things if that wasn't happening So please confirm for sure that it's happening and update all your ash deps etc And then create a repro and I'll look into it ๐Ÿ™‚
MortenLund
MortenLundOPโ€ข2mo ago
Okay, I will try to make sure this is not related to SQLite3 or my way of implementing it.
ZachDaniel
ZachDanielโ€ข2mo ago
That chart should be updated also to point to rollback on error from after action Can you open an issue/PR for that?
MortenLund
MortenLundOPโ€ข2mo ago
Done ๐Ÿ™‚
MortenLund
MortenLundOPโ€ข2mo ago
I made a test that is behaving in the way described. Maybe its by design and I setup something incorrectly. https://github.com/ash-project/ash_sqlite/pull/175
GitHub
Expected this to leave any records behind by m0rt3nlund ยท Pull Req...
Contributor checklist Leave anything that you believe does not apply unchecked. I accept the AI Policy, or AI was not used in the creation of this PR. Bug fixes include regression tests Chores ...
ZachDaniel
ZachDanielโ€ข2mo ago
Haven't looked yet but do you see a transaction starting/stopping? In the logs?
MortenLund
MortenLundOPโ€ข2mo ago
No i do not see any transaction messages and actually stupidly assumed it was just hidden or implemented differently for sqlite ๐Ÿ™‚ I will look at the details if i get time this weekend.
MortenLund
MortenLundOPโ€ข2mo ago
Been looking through the code for ash_sqlite3 and my understanding is that there is no transaction support? I noticed can?(, :transact), do: false and there is a PR for enabling transaction per resource basis? https://github.com/ash-project/ash_sqlite/pull/95
ZachDaniel
ZachDanielโ€ข2mo ago
oh. uh...yep you're right sorry ๐Ÿ˜…

Did you find this page helpful?