Add a calling card to @transaction for runtime determination.

master
voussoir 2022-03-22 22:17:32 -07:00
parent 9c9123e2d2
commit 1026d4414c
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 5 additions and 0 deletions

View File

@ -45,6 +45,10 @@ def transaction(method):
This decorator adds the keyword argument 'commit' to your function, so that This decorator adds the keyword argument 'commit' to your function, so that
callers can commit it immediately. callers can commit it immediately.
This decorator adds the attribute 'is_worms_transaction = True' to your
function. You can use this to distinguish readonly vs writing methods during
runtime.
If you want to raise an exception without rolling back, you can return If you want to raise an exception without rolling back, you can return
worms.raise_without_rollback(exc). This could be useful if you want to worms.raise_without_rollback(exc). This could be useful if you want to
preserve some kind of attempted action in the database while still raising preserve some kind of attempted action in the database while still raising
@ -81,6 +85,7 @@ def transaction(method):
database.release_savepoint(savepoint=savepoint_id) database.release_savepoint(savepoint=savepoint_id)
return result return result
wrapped_transaction.is_worms_transaction = True
return wrapped_transaction return wrapped_transaction
class Database(metaclass=abc.ABCMeta): class Database(metaclass=abc.ABCMeta):