hooks/syncschema.py
changeset 8724 1beab80aed23
parent 8696 0bb18407c053
parent 8715 ab0cd0765076
child 8821 c4aa23af0baa
equal deleted inserted replaced
8721:b399c87df63c 8724:1beab80aed23
   242     """after adding a CWEType entity:
   242     """after adding a CWEType entity:
   243     * add it to the instance's schema
   243     * add it to the instance's schema
   244     * create the necessary table
   244     * create the necessary table
   245     * set creation_date and modification_date by creating the necessary
   245     * set creation_date and modification_date by creating the necessary
   246       CWAttribute entities
   246       CWAttribute entities
   247     * add owned_by relation by creating the necessary CWRelation entity
   247     * add <meta rtype> relation by creating the necessary CWRelation entity
   248     """
   248     """
   249     entity = None # make pylint happy
   249     entity = None # make pylint happy
   250 
   250 
   251     def precommit_event(self):
   251     def precommit_event(self):
   252         session = self.session
   252         session = self.session
   268             try:
   268             try:
   269                 rschema = schema[rtype]
   269                 rschema = schema[rtype]
   270             except KeyError:
   270             except KeyError:
   271                 self.critical('rtype %s was not handled at cwetype creation time', rtype)
   271                 self.critical('rtype %s was not handled at cwetype creation time', rtype)
   272                 continue
   272                 continue
       
   273             if not rschema.rdefs:
       
   274                 self.warning('rtype %s has no relation definition yet', rtype)
       
   275                 continue
   273             sampletype = rschema.subjects()[0]
   276             sampletype = rschema.subjects()[0]
   274             desttype = rschema.objects()[0]
   277             desttype = rschema.objects()[0]
   275             rdef = copy(rschema.rdef(sampletype, desttype))
   278             try:
       
   279                 rdef = copy(rschema.rdef(sampletype, desttype))
       
   280             except KeyError:
       
   281                 # this combo does not exist because this is not a universal META_RTYPE
       
   282                 continue
   276             rdef.subject = _MockEntity(eid=entity.eid)
   283             rdef.subject = _MockEntity(eid=entity.eid)
   277             mock = _MockEntity(eid=None)
   284             mock = _MockEntity(eid=None)
   278             ss.execschemarql(session.execute, mock, ss.rdef2rql(rdef, cmap, gmap))
   285             ss.execschemarql(session.execute, mock, ss.rdef2rql(rdef, cmap, gmap))
   279 
   286 
   280     def revertprecommit_event(self):
   287     def revertprecommit_event(self):