From 1026d4414c7b8db67b3b3edf5cd0afaedd84b48c Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 22 Mar 2022 22:17:32 -0700 Subject: [PATCH] Add a calling card to @transaction for runtime determination. --- voussoirkit/worms.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index db87327..3f54cb5 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -45,6 +45,10 @@ def transaction(method): This decorator adds the keyword argument 'commit' to your function, so that 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 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 @@ -81,6 +85,7 @@ def transaction(method): database.release_savepoint(savepoint=savepoint_id) return result + wrapped_transaction.is_worms_transaction = True return wrapped_transaction class Database(metaclass=abc.ABCMeta):