Commits

Mike Bayer committed 361ee99

need to return begin() for enter/exit hook

  • Participants
  • Parent commits 3c05d62
  • Branches user_defined_state

Comments (0)

Files changed (1)

File lib/sqlalchemy/orm/session.py

                 raise sa_exc.InvalidRequestError("A transaction is already begun.  Use subtransactions=True to allow subtransactions.")
         else:
             self.transaction = SessionTransaction(self, nested=nested, autoflush=_autoflush)
-
+        return self.transaction  # needed for __enter__/__exit__ hook
 
     def begin_nested(self):
         """Begin a `nested` transaction on this Session.
         if len(flush_context.tasks) == 0:
             return
         
-        self.begin(subtransactions=True, _autoflush=False)
-        flush_context.transaction = transaction = self.transaction
+        flush_context.transaction = transaction = self.begin(subtransactions=True, _autoflush=False)
         try:
             flush_context.execute()