]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added a new SessionExtension hook called after_attach().
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 19 Jul 2008 15:47:21 +0000 (15:47 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 19 Jul 2008 15:47:21 +0000 (15:47 +0000)
This is called at the point of attachment for objects
via save(), update(), delete(), and merge()
(backported from 0.5).

CHANGES
VERSION
lib/sqlalchemy/orm/session.py
test/orm/session.py

diff --git a/CHANGES b/CHANGES
index ebc85b42972565dc5b8ed01cb3294c9c353e7180..102e71c94f14dbae401f8f9449e4e692aa772bdf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,11 @@ CHANGES
     - 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')]).
diff --git a/VERSION b/VERSION
index ef52a648073dd38aebdd7505edb3ba36e8bfd230..f90568270955379549eb7ee163cee9470f285188 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.4.6
+0.4.7
index 3dfe0411c379fb4c0a4eaa08879aa77095759da8..641f87df4b9d866756dbdf296771d3bce6daebd8 100644 (file)
@@ -135,6 +135,9 @@ class SessionExtension(object):
         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.
 
@@ -1123,6 +1126,9 @@ class Session(object):
                 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
index eae0eab1124df59ad9e3381131ffd99deb196747..ca9aae835d17398b08fcea04297ea5d35fd005c6 100644 (file)
@@ -890,18 +890,21 @@ class SessionTest(TestBase, AssertsExecutionResults):
                 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'