[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
--- 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:
--- 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 = '??'
--- 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'])