# HG changeset patch # User Sylvain Thénault # Date 1455269964 -3600 # Node ID 012e6c7d02ef3f61bf5486b5383b4bf993ee682f # Parent 2a8884f3be3d5db5d394170375cc937fe188d33b [migration] test if entity type has been in the deleted in the transaction should protect both clauses else we may attempt to execute the UPDATE query on a table which has been deleted. Closes #10692374 diff -r 2a8884f3be3d -r 012e6c7d02ef hooks/syncschema.py --- a/hooks/syncschema.py Fri Feb 12 10:39:14 2016 +0100 +++ b/hooks/syncschema.py Fri Feb 12 10:39:24 2016 +0100 @@ -606,21 +606,22 @@ # relations, but only if it's the last instance for this relation type # for other relations if (rschema.final or rschema.inlined): - rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' - 'R eid %%(r)s, X from_entity E, E eid %%(e)s' - % rdeftype, - {'r': rschema.eid, 'e': rdef.subject.eid}) - if rset[0][0] == 0 and not cnx.deleted_in_transaction(rdef.subject.eid): - ptypes = cnx.transaction_data.setdefault('pendingrtypes', set()) - ptypes.add(rschema.type) - DropColumn.get_instance(cnx).add_data((str(rdef.subject), str(rschema))) - elif rschema.inlined: - cnx.system_sql('UPDATE %s%s SET %s%s=NULL WHERE ' - 'EXISTS(SELECT 1 FROM entities ' - ' WHERE eid=%s%s AND type=%%(to_etype)s)' - % (SQL_PREFIX, rdef.subject, SQL_PREFIX, rdef.rtype, - SQL_PREFIX, rdef.rtype), - {'to_etype': rdef.object.type}) + if not cnx.deleted_in_transaction(rdef.subject.eid): + rset = execute('Any COUNT(X) WHERE X is %s, X relation_type R, ' + 'R eid %%(r)s, X from_entity E, E eid %%(e)s' + % rdeftype, + {'r': rschema.eid, 'e': rdef.subject.eid}) + if rset[0][0] == 0: + ptypes = cnx.transaction_data.setdefault('pendingrtypes', set()) + ptypes.add(rschema.type) + DropColumn.get_instance(cnx).add_data((str(rdef.subject), str(rschema))) + elif rschema.inlined: + cnx.system_sql('UPDATE %s%s SET %s%s=NULL WHERE ' + 'EXISTS(SELECT 1 FROM entities ' + ' WHERE eid=%s%s AND type=%%(to_etype)s)' + % (SQL_PREFIX, rdef.subject, SQL_PREFIX, rdef.rtype, + SQL_PREFIX, rdef.rtype), + {'to_etype': rdef.object.type}) elif lastrel: DropRelationTable(cnx, str(rschema)) else: diff -r 2a8884f3be3d -r 012e6c7d02ef server/test/data-migractions/migratedapp/schema.py --- a/server/test/data-migractions/migratedapp/schema.py Fri Feb 12 10:39:14 2016 +0100 +++ b/server/test/data-migractions/migratedapp/schema.py Fri Feb 12 10:39:24 2016 +0100 @@ -211,3 +211,8 @@ class same_as(RelationDefinition): subject = ('Societe',) object = 'ExternalUri' + +class inlined_rel(RelationDefinition): + subject = object = 'Folder2' + inlined = True + cardinality = '??' diff -r 2a8884f3be3d -r 012e6c7d02ef server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Fri Feb 12 10:39:14 2016 +0100 +++ b/server/test/unittest_migractions.py Fri Feb 12 10:39:24 2016 +0100 @@ -276,7 +276,7 @@ 'description', 'description_format', 'eid', 'filed_under2', 'has_text', - 'identity', 'in_basket', 'is', 'is_instance_of', + 'identity', 'in_basket', 'inlined_rel', 'is', 'is_instance_of', 'modification_date', 'name', 'owned_by']) self.assertCountEqual([str(rs) for rs in self.schema['Folder2'].object_relations()], ['filed_under2', 'identity'])