1. diana clarke
  2. sqlalchemy-2422

Commits

Mike Bayer  committed 17a5c1b

- Added a new SessionExtension hook called after_attach().
This is called at the point of attachment for objects
via save(), update(), delete(), and merge()
(backported from 0.5).

  • Participants
  • Parent commits 5fa46d5
  • Branches rel_0_4

Comments (0)

Files changed (4)

File CHANGES

View file
     - Removed erroneous 'self' reference when raising
       UnmappedColumnError during flush() operation.
 
+    - Added a new SessionExtension hook called after_attach().
+      This is called at the point of attachment for objects
+      via save(), update(), delete(), and merge() 
+      (backported from 0.5).
+
 - sql
     - Fixed bug when calling select([literal('foo')])
       or select([bindparam('foo')]).

File VERSION

View file
-0.4.6
+0.4.7

File lib/sqlalchemy/orm/session.py

View file
         engine level transaction is begun on a connection.
         """
 
+    def after_attach(self, session, instance):
+        """Execute after an instance is attached to a session."""
+
 class SessionTransaction(object):
     """Represents a Session-level Transaction.
 
                 self.identity_map[key] = instance
             instance._sa_session_id = self.hash_key
 
+            if self.extension is not None:
+                self.extension.after_attach(self, instance)
+
     def _unattach(self, instance):
         if instance._sa_session_id == self.hash_key:
             del instance._sa_session_id

File test/orm/session.py

View file
                 log.append('after_flush_postexec')
             def after_begin(self, session, transaction, connection):
                 log.append('after_begin')
+            def after_attach(self, session, instance):
+                log.append('after_attach')
+
         sess = create_session(extension = MyExt())
         u = User()
         sess.save(u)
         sess.flush()
-        assert log == ['before_flush', 'after_begin', 'after_flush', 'before_commit', 'after_commit', 'after_flush_postexec']
+        assert log == ['after_attach', 'before_flush', 'after_begin', 'after_flush', 'before_commit', 'after_commit', 'after_flush_postexec']
 
         log = []
         sess = create_session(transactional=True, extension=MyExt())
         u = User()
         sess.save(u)
         sess.flush()
-        assert log == ['before_flush', 'after_begin', 'after_flush', 'after_flush_postexec']
+        assert log == ['after_attach', 'before_flush', 'after_begin', 'after_flush', 'after_flush_postexec']
 
         log = []
         u.user_name = 'ed'