hooks/integrity.py
branchstable
changeset 5449 a7e1b316af03
parent 5448 9bf648d678cd
child 5450 269dcd14b92c
equal deleted inserted replaced
5448:9bf648d678cd 5449:a7e1b316af03
   162 class _CheckConstraintsOp(hook.LateOperation):
   162 class _CheckConstraintsOp(hook.LateOperation):
   163     """check a new relation satisfy its constraints
   163     """check a new relation satisfy its constraints
   164     """
   164     """
   165     def precommit_event(self):
   165     def precommit_event(self):
   166         session = self.session
   166         session = self.session
   167         for values in session.transaction_data['check_constraints_op']:
   167         for values in session.transaction_data.pop('check_constraints_op'):
   168             eidfrom, rtype, eidto = values[:3]
   168             eidfrom, rtype, eidto = values[:3]
   169             # first check related entities have not been deleted in the same
   169             # first check related entities have not been deleted in the same
   170             # transaction
   170             # transaction
   171             if session.deleted_in_transaction(eidfrom):
   171             if session.deleted_in_transaction(eidfrom):
   172                 return
   172                 return
   223         for attr in self.entity.edited_attributes:
   223         for attr in self.entity.edited_attributes:
   224             if eschema.subjrels[attr].final:
   224             if eschema.subjrels[attr].final:
   225                 constraints = [c for c in eschema.rdef(attr).constraints
   225                 constraints = [c for c in eschema.rdef(attr).constraints
   226                                if isinstance(c, (RQLUniqueConstraint, RQLConstraint))]
   226                                if isinstance(c, (RQLUniqueConstraint, RQLConstraint))]
   227                 if constraints:
   227                 if constraints:
   228                     hook.set_operation(self._cw, 'check_constraint_op',
   228                     hook.set_operation(self._cw, 'check_constraints_op',
   229                                        (self.entity.eid, attr, None) + tuple(constraints),
   229                                        (self.entity.eid, attr, None) + tuple(constraints),
   230                                        _CheckConstraintsOp)
   230                                        _CheckConstraintsOp)
   231 
   231 
   232 
   232 
   233 class CheckUniqueHook(IntegrityHook):
   233 class CheckUniqueHook(IntegrityHook):