hooks/syncschema.py
branchstable
changeset 9600 bde625698f44
parent 9588 fe267b7336f3
parent 9565 fa00fc251d57
child 9635 aaf099172bb9
equal deleted inserted replaced
9599:13dd3a57dabb 9600:bde625698f44
   648     def precommit_event(self):
   648     def precommit_event(self):
   649         session = self.session
   649         session = self.session
   650         rdef = self.rdef
   650         rdef = self.rdef
   651         # in-place modification of in-memory schema first
   651         # in-place modification of in-memory schema first
   652         _set_modifiable_constraints(rdef)
   652         _set_modifiable_constraints(rdef)
   653         rdef.constraints.remove(self.oldcstr)
   653         if self.oldcstr in rdef.constraints:
       
   654             rdef.constraints.remove(self.oldcstr)
       
   655         else:
       
   656             self.critical('constraint %s for rdef %s was missing or already removed',
       
   657                           self.oldcstr, rdef)
   654         # then update database: alter the physical schema on size/unique
   658         # then update database: alter the physical schema on size/unique
   655         # constraint changes
   659         # constraint changes
   656         syssource = session.cnxset.source('system')
   660         syssource = session.cnxset.source('system')
   657         cstrtype = self.oldcstr.type()
   661         cstrtype = self.oldcstr.type()
   658         if cstrtype == 'SizeConstraint':
   662         if cstrtype == 'SizeConstraint':
  1130 
  1134 
  1131     def __call__(self):
  1135     def __call__(self):
  1132         if self._cw.deleted_in_transaction(self.eidfrom):
  1136         if self._cw.deleted_in_transaction(self.eidfrom):
  1133             return
  1137             return
  1134         schema = self._cw.vreg.schema
  1138         schema = self._cw.vreg.schema
  1135         entity = self._cw.entity_from_eid(self.eidto)
       
  1136         rdef = schema.schema_by_eid(self.eidfrom)
  1139         rdef = schema.schema_by_eid(self.eidfrom)
  1137         try:
  1140         try:
  1138             cstr = rdef.constraint_by_type(entity.type)
  1141             cstr = rdef.constraint_by_eid(self.eidto)
  1139         except IndexError:
  1142         except ValueError:
  1140             self._cw.critical('constraint type no more accessible')
  1143             self._cw.critical('constraint no more accessible')
  1141         else:
  1144         else:
  1142             CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr)
  1145             CWConstraintDelOp(self._cw, rdef=rdef, oldcstr=cstr)
  1143 
  1146 
  1144 # unique_together constraints
  1147 # unique_together constraints
  1145 # XXX: use setoperations and before_add_relation here (on constraint_of and relations)
  1148 # XXX: use setoperations and before_add_relation here (on constraint_of and relations)