summaryrefslogtreecommitdiff
path: root/src/mailman/database/transaction.py
diff options
context:
space:
mode:
authorBarry Warsaw2015-04-15 10:05:35 -0400
committerBarry Warsaw2015-04-15 10:05:35 -0400
commit67fd8d6dbcf8849b3c2f8cb42a10aed465ace76c (patch)
tree97eca0ae33c97015e4d2fca31e7792e2a929fa8d /src/mailman/database/transaction.py
parent7317b94a0b746f0287ecbc5654ec544ce0112adb (diff)
parent3e7dffa750a3e7bb15ac10b711832696554ba03a (diff)
downloadmailman-67fd8d6dbcf8849b3c2f8cb42a10aed465ace76c.tar.gz
mailman-67fd8d6dbcf8849b3c2f8cb42a10aed465ace76c.tar.zst
mailman-67fd8d6dbcf8849b3c2f8cb42a10aed465ace76c.zip
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.