Non obvious causes of a transaction conflict?

Anvil’s Data Tables are backed by Postgres, and anvil.table.Transactions are fully SERIALIZABLE. In this mode, Postgres is conservative in identifying conflicts (ie it will sometimes abort an entirely valid transaction), and we’ve found you can get false-positive cross-talk between different apps using the same shared hosting infrastructure. So it’s entirely possible for your app to see transaction rollbacks when nothing else is touching your tables! It’s always a good idea to expect that any transaction might need to retry, and do rapid transactions inside @anvil.tables.in_transaction functions that automatically retry. (We’re working on ways to improve transaction performance and reduce false-positive aborts, but this advice will still apply!)

4 Likes