Commits

Rufus Pollock committed 6d36e5c

[sqlalchemy,bugfix][s]: fix even more subtle bug whereby changeobject not updated correctly if session.flush() called before setting a value even though commit then happens later.

* Again bit concerned that i do not really understand what is going on inside sqlalchemy here.

Comments (0)

Files changed (2)

vdm/sqlalchemy/model.py

                 operation_type=ChangeObject.OperationType.CREATE
                 )
 
+    def before_commit(self, session):
+        for obj in versioned_objects(session.dirty):
+            create_version(obj, session)
+        for obj in versioned_objects(session.deleted):
+            create_version(obj, session,
+                operation_type=ChangeObject.OperationType.DELETE
+                )
+        for obj in versioned_objects(session.new):
+            create_version(obj, session,
+                operation_type=ChangeObject.OperationType.CREATE
+                )
+

vdm/test/sqlalchemy/test_demo.py

         p2 = Package(name=self.name2, title=self.title1, license=lic1)
         session.add_all([lic1,lic2,p1,p2])
 
+        # Call session.flush here as this is, apparently, even more demanding
+        # What is weird is that this should work whether we call flush here or
+        # after p1.title = .. as we call commit below but that is not true!!
+        session.flush()
+
         # test vdm by flushing now and then making another change
         p1.title = self.title1
-        # What is weird is that this should work whether we call flush here or
-        # not since we call commit below but that is not true!!
-        session.flush()
+        # call before rather than after title set (see comment above)
+        # session.flush()
 
         logger.debug('***** Committing/Flushing Rev 1')
         session.commit()