summaryrefslogtreecommitdiff
path: root/src/mailman/database/transaction.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/database/transaction.py')
-rw-r--r--src/mailman/database/transaction.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mailman/database/transaction.py b/src/mailman/database/transaction.py
index b96562d3f..fef76b73c 100644
--- a/src/mailman/database/transaction.py
+++ b/src/mailman/database/transaction.py
@@ -19,6 +19,7 @@
__all__ = [
'dbconnection',
+ 'flush',
'transaction',
'transactional',
]
@@ -63,6 +64,22 @@ def transactional(function):
+@contextmanager
+def flush():
+ """Context manager for flushing SQLAlchemy.
+
+ We need this for SA whereas we didn't need it for Storm because the latter
+ did auto-reloads. However, in SA this is needed when we add or delete
+ objects from the database. Use it when you need the id after adding, or
+ when you want to be sure the object won't be found after a delete.
+
+ This is lighter weight than committing the transaction.
+ """
+ yield
+ config.db.store.flush()
+
+
+
def dbconnection(function):
"""Decorator for getting at the database connection.