[migration] fix rename_entity_type bug: not putting eids of relation deleted using sql query may cause later error on commit, complaining on missing relation on an entity which has been actually deleted stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 06 Aug 2010 17:37:06 +0200
branchstable
changeset 6074 f2580c7abc26
parent 6073 bf684f1022bf
child 6075 6ebecb217efe
[migration] fix rename_entity_type bug: not putting eids of relation deleted using sql query may cause later error on commit, complaining on missing relation on an entity which has been actually deleted
server/migractions.py
--- a/server/migractions.py	Fri Aug 06 17:35:02 2010 +0200
+++ b/server/migractions.py	Fri Aug 06 17:37:06 2010 +0200
@@ -876,7 +876,15 @@
                 self.sqlexec('UPDATE %s_relation SET eid_to=%s WHERE eid_to=%s'
                              % (rtype, new.eid, oldeid), ask_confirm=False)
             # delete relations using SQL to avoid relations content removal
-            # triggered by schema synchronization hooks
+            # triggered by schema synchronization hooks. Should add deleted eids
+            # into pending eids else we may get some validation error on commit
+            # since integrity hooks may think some required relation is
+            # missing...
+            pending = self.session.transaction_data.setdefault('pendingeids', set())
+            for eid, in self.sqlexec('SELECT cw_eid FROM cw_CWRelation '
+                                     'WHERE cw_from_entity=%(eid)s OR cw_to_entity=%(eid)s',
+                                     {'eid': oldeid}, ask_confirm=False):
+                pending.add(eid)
             self.sqlexec('DELETE FROM cw_CWRelation '
                          'WHERE cw_from_entity=%(eid)s OR cw_to_entity=%(eid)s',
                          {'eid': oldeid}, ask_confirm=False)