diff options
| author | Barry Warsaw | 2015-04-14 18:54:05 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2015-04-14 18:54:05 -0400 |
| commit | a9a9fd2c778aa8cfde5f244420602a70dab44cfa (patch) | |
| tree | cf66ad5939a5c9eaa9342036a971d745d5a89398 /src/mailman/database/transaction.py | |
| parent | eab98485ec133dcc745618e4fd5b6054c902af05 (diff) | |
| download | mailman-a9a9fd2c778aa8cfde5f244420602a70dab44cfa.tar.gz mailman-a9a9fd2c778aa8cfde5f244420602a70dab44cfa.tar.zst mailman-a9a9fd2c778aa8cfde5f244420602a70dab44cfa.zip | |
Diffstat (limited to 'src/mailman/database/transaction.py')
| -rw-r--r-- | src/mailman/database/transaction.py | 17 |
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. |
