Hi,
I have built a simulator with multi-user. Until a few days all worked well.
But no there seems to be a change in the database:
I get several times the error:
TableError: Internal database error: ERROR: canceling statement due to user request
Seems to be a bug in there - Anvil can you check please.
Thanks Aaron
Hi Aaron,
Can you confirm that this error is still occurring? Can you share the code that is causing the error?
Hi Brooke,
unfortunately I cannot share the code. I will test it again and tell you the results.
Have you found something on your side?
so far it is running fine
I’ve also been getting this (and another similar error) quite a bit lately. It happens sporadically. I do think it’s an Anvil bug.
My workaround has been to write a wrapper function that catches anvil.tables.TableError
exceptions and retries them.
Interesting, can you show us your solution.
I have tested yesterday and never got the error again. We are soon to launch and it would be very bad, if it shows again with customers.
def retry_db(function, *args, db_retries=3, db_sleep_for=5, **kwargs):
"""
Calls a function that requires at least one database call, with specified arguments.
Retries up to `db_retries` times, waiting `db_sleep_for` seconds between each attempt,
otherwise raising the final error encountered.
"""
for _ in range(db_retries):
try:
with anvil.tables.Transaction() as txn:
return function(*args, **kwargs)
except (tables.TableError, tables.TransactionConflict) as e:
time.sleep(db_sleep_for)
raise e
Its function
argument can be any function that reads/writes the DB, and will be executed in a transaction. For this reason function
should be a fairly atomic operation, like a row update.
I’ve been using it in the following ways:
-
row['property'] = value
becomesretry_db(row.update, property=value)
-
row.update(prop1=val1, prop2=val2)
becomesretry_db(row.update, prop1=val1, prop2=val2)
Using this wrapper has completely eliminated the error you mentioned as well as the one I linked to in my other post. These errors have been sporadic and transient, and therefore difficult to debug due to not being able to reproduce on command.
Thank you very much - that helps a lot!!!
Today it happend again (just in a customer-presentation).