summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/events.py20
-rw-r--r--lib/sqlalchemy/orm/session.py10
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py
index 67f6d6431..61517770f 100644
--- a/lib/sqlalchemy/orm/events.py
+++ b/lib/sqlalchemy/orm/events.py
@@ -955,6 +955,26 @@ class SessionEvents(event.Events):
def _remove(cls, identifier, target, fn):
raise NotImplementedError("Removal of session events not yet implemented")
+ def after_transaction_create(self, session, transaction):
+ """Execute when a new :class:`.SessionTransaction` is created.
+
+ :param session: the target :class:.`Session`.
+ :param transaction: the target :class:`.SessionTransaction`.
+
+ .. versionadded:: 0.8
+
+ """
+
+ def after_transaction_end(self, session, transaction):
+ """Execute when the span of a :class:`.SessionTransaction` ends.
+
+ :param session: the target :class:.`Session`.
+ :param transaction: the target :class:`.SessionTransaction`.
+
+ .. versionadded:: 0.8
+
+ """
+
def before_commit(self, session):
"""Execute before commit is called.
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index e0f79cd8a..36ff5fc84 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -150,6 +150,9 @@ class SessionTransaction(object):
if self.session._enable_transaction_accounting:
self._take_snapshot()
+ if self.session.dispatch.after_transaction_create:
+ self.session.dispatch.after_transaction_create(self.session, self)
+
@property
def is_active(self):
return self.session is not None and self._active
@@ -379,9 +382,14 @@ class SessionTransaction(object):
connection.close()
else:
transaction.close()
+
+ self._deactivate()
+ if self.session.dispatch.after_transaction_end:
+ self.session.dispatch.after_transaction_end(self.session, self)
+
+ if self._parent is None:
if not self.session.autocommit:
self.session.begin()
- self._deactivate()
self.session = None
self._connections = None