1121 if self._cw.added_in_transaction(self.eidfrom): |
1121 if self._cw.added_in_transaction(self.eidfrom): |
1122 # used by get_constraints() which is called in CWAttributeAddOp |
1122 # used by get_constraints() which is called in CWAttributeAddOp |
1123 self._cw.transaction_data.setdefault(self.eidfrom, []).append(self.eidto) |
1123 self._cw.transaction_data.setdefault(self.eidfrom, []).append(self.eidto) |
1124 |
1124 |
1125 |
1125 |
1126 class BeforeDeleteConstrainedByHook(SyncSchemaHook): |
1126 class BeforeDeleteCWConstraintHook(SyncSchemaHook): |
1127 __regid__ = 'syncdelconstrainedby' |
1127 __regid__ = 'syncdelcwconstraint' |
1128 __select__ = SyncSchemaHook.__select__ & hook.match_rtype('constrained_by') |
1128 __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint') |
1129 events = ('before_delete_relation',) |
1129 events = ('before_delete_entity',) |
1130 |
1130 |
1131 def __call__(self): |
1131 def __call__(self): |
1132 if self._cw.deleted_in_transaction(self.eidfrom): |
1132 entity = self.entity |
1133 return |
|
1134 schema = self._cw.vreg.schema |
1133 schema = self._cw.vreg.schema |
1135 entity = self._cw.entity_from_eid(self.eidto) |
|
1136 rdef = schema.schema_by_eid(self.eidfrom) |
|
1137 try: |
1134 try: |
|
1135 # KeyError, e.g. composite chain deletion |
|
1136 rdef = schema.schema_by_eid(entity.reverse_constrained_by[0].eid) |
|
1137 # IndexError |
1138 cstr = rdef.constraint_by_type(entity.type) |
1138 cstr = rdef.constraint_by_type(entity.type) |
1139 except IndexError: |
1139 except (IndexError, KeyError): |
1140 self._cw.critical('constraint type no more accessible') |
1140 self._cw.critical('constraint type no more accessible') |
1141 else: |
1141 else: |
1142 CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr) |
1142 CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr) |
1143 |
1143 |
1144 # unique_together constraints |
1144 # unique_together constraints |