Commits

Jason Kirtland  committed 058f243

Added SessionExtention.right_before_commit

  • Participants
  • Parent commits 102de80
  • Branches granular-session-ext

Comments (0)

Files changed (3)

File lib/sqlalchemy/orm/interfaces.py

         Note that this may not be per-flush if a longer running
         transaction is ongoing."""
 
+    def right_before_commit(self, session):
+        """Actually execute right before commit is called.
+
+        Executes where you'd expect :meth:`before_commit` to.  At time of
+        invocation, all flushes will be complete.  Immediately after
+        invocation, each DB connection will receive a .commit(), ending the
+        transaction.
+
+        Note that this may not be per-flush if a longer running
+        transaction is ongoing.
+        """
+
     def after_commit(self, session):
         """Execute after a commit has occured.
         

File lib/sqlalchemy/orm/session.py

             self._prepare_impl()
 
         if self._parent is None or self.nested:
+            for ext in self.session.extensions:
+                ext.right_before_commit(self.session)
+
             for t in set(self._connections.values()):
                 t[1].commit()
 

File test/orm/test_session.py

         class MyExt(sa.orm.session.SessionExtension):
             def before_commit(self, session):
                 log.append('before_commit')
+            def right_before_commit(self, session):
+                log.append('right_before_commit')
             def after_commit(self, session):
                 log.append('after_commit')
             def after_rollback(self, session):
             'after_begin',
             'after_flush',
             'before_commit',
+            'right_before_commit',
             'after_commit',
             'after_flush_postexec',
             ]
         u.name = 'ed'
         sess.commit()
         assert log == ['before_commit', 'before_flush', 'after_flush',
-                       'after_flush_postexec', 'after_commit']
+                       'after_flush_postexec', 'right_before_commit', 'after_commit']
         log = []
         sess.commit()
-        assert log == ['before_commit', 'after_commit']
+        assert log == ['before_commit', 'right_before_commit', 'after_commit']
         log = []
         sess.query(User).delete()
         assert log == ['after_begin', 'after_bulk_delete']