Is there a way to tell whether the database is in the middle of a transaction?

Then wouldn’t this work? without a global variable.

def nested_transaction(fn):
  @wraps(fn)
  def wrapped(*args,**kwargs):
      try:
        with anvil.tables.Transaction() as txn:
          return_val = fn(*args,**kwargs)
          return return_val
      except <nested transaction exception>:
        return_val = fn(*args,**kwargs)
        return return_val
  return wrapped
1 Like