cubicweb/hooks/syncschema.py
changeset 11129 97095348b3ee
parent 11106 012e6c7d02ef
parent 11057 0b59724cb3f2
child 11231 b0dcbc7cf410
--- a/cubicweb/hooks/syncschema.py	Thu Feb 11 21:59:49 2016 +0100
+++ b/cubicweb/hooks/syncschema.py	Wed Feb 17 13:45:34 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: