Read this for a description of false positives in transactions (and the entire thread for various people’s experiences with best practices using transactions): Non obvious causes of a transaction conflict? - #22 You’ll find that the general advice is to keep your transaction functions tiny and not try to combine them with other things.
I started out doing what the docs showed, and ran into transaction conflicts even though I was the only user of the app.
Looks like I forgot the quotes around id. I did warn you it was untested code.