[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
--- 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)