873 pendingrtypes = cnx.transaction_data.get('pendingrtypes', ()) |
873 pendingrtypes = cnx.transaction_data.get('pendingrtypes', ()) |
874 # delete remaining relations: if user can delete the entity, he can |
874 # delete remaining relations: if user can delete the entity, he can |
875 # delete all its relations without security checking |
875 # delete all its relations without security checking |
876 with cnx.security_enabled(read=False, write=False): |
876 with cnx.security_enabled(read=False, write=False): |
877 in_eids = ','.join([str(_e.eid) for _e in entities]) |
877 in_eids = ','.join([str(_e.eid) for _e in entities]) |
878 for rschema, _, role in entities[0].e_schema.relation_definitions(): |
878 with cnx.running_hooks_ops(): |
879 if rschema.rule: |
879 for rschema, _, role in entities[0].e_schema.relation_definitions(): |
880 continue # computed relation |
880 if rschema.rule: |
881 rtype = rschema.type |
881 continue # computed relation |
882 if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes: |
882 rtype = rschema.type |
883 continue |
883 if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes: |
884 if role == 'subject': |
884 continue |
885 # don't skip inlined relation so they are regularly |
885 if role == 'subject': |
886 # deleted and so hooks are correctly called |
886 # don't skip inlined relation so they are regularly |
887 rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids) |
887 # deleted and so hooks are correctly called |
888 else: |
888 rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids) |
889 rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids) |
889 else: |
890 try: |
890 rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids) |
891 cnx.execute(rql, build_descr=False) |
891 try: |
892 except ValidationError: |
892 cnx.execute(rql, build_descr=False) |
893 raise |
893 except ValidationError: |
894 except Unauthorized: |
|
895 self.exception('Unauthorized exception while cascading delete for entity %s. ' |
|
896 'RQL: %s.\nThis should not happen since security is disabled here.', |
|
897 entities, rql) |
|
898 raise |
|
899 except Exception: |
|
900 if self.config.mode == 'test': |
|
901 raise |
894 raise |
902 self.exception('error while cascading delete for entity %s. RQL: %s', |
895 except Unauthorized: |
903 entities, rql) |
896 self.exception('Unauthorized exception while cascading delete for entity %s. ' |
|
897 'RQL: %s.\nThis should not happen since security is disabled here.', |
|
898 entities, rql) |
|
899 raise |
|
900 except Exception: |
|
901 if self.config.mode == 'test': |
|
902 raise |
|
903 self.exception('error while cascading delete for entity %s. RQL: %s', |
|
904 entities, rql) |
904 |
905 |
905 def init_entity_caches(self, cnx, entity, source): |
906 def init_entity_caches(self, cnx, entity, source): |
906 """add entity to connection entities cache and repo's extid cache. |
907 """add entity to connection entities cache and repo's extid cache. |
907 Return entity's ext id if the source isn't the system source. |
908 Return entity's ext id if the source isn't the system source. |
908 """ |
909 """ |