I have a server function running in a transaction, using @anvil.tables.in_transaction
. That server function is the only place where a particular data table field is updated. I’m getting intermittent transaction conflicts on that line. Everything is still in alpha testing, so I’m pretty much the only person using the app at the moment, so an actual transaction conflict isn’t likely.
What I’m looking for are the non-obvious causes of transaction conflicts, the sort of gotchas that might crop up even when only a single person is using the app. Is there a way the client might be making parallel calls to the server function, for example?
The server function is being called from a form’s init method, as well as in response to a button click.
I thought at first that I was clicking the button multiple times (this was on a mobile device), but I have tried replicating that and it doesn’t cause the transaction conflict.
Are there other reasons you might get a transaction conflict with a server call initiated by button press?
Here’s the server function:
@anvil.server.callable
@anvil.tables.in_transaction
def get_progress(order_item_id):
order_item = app_tables.orderitems.get(order_item_id=order_item_id)
if not order_item:
raise ValueError("Invalid order item")
set_mystery_being_played(order_item)
# The following line is the one triggering the transaction conflict
order_item['last_accessed'] = datetime.datetime.now()
rendered = process_bbcode(order_item['stage']['data']['message'], order_item)
return (order_item['stage'], rendered, order_item['variables'], app_tables.stage_submissions.search(tables.order_by('datetime'), order_item=order_item))