# HG changeset patch # User Sylvain Thénault # Date 1409242348 -7200 # Node ID 3e5addc72575984e246f4a5e64e76ef1323f41d8 # Parent e0f1c5697221d7ee93a29dff7811fb0181dfb468 Fix test migration crash waiting to happen due to inferred relations Avoid crashing when a relation definition which is already known (due to being inferred) gets explicitly added. As explained in a comment, this would deserve more thinking, but at least this fixes a test failure with computed relations. diff -r e0f1c5697221 -r 3e5addc72575 hooks/syncschema.py --- a/hooks/syncschema.py Thu Aug 28 07:42:10 2014 +0200 +++ b/hooks/syncschema.py Thu Aug 28 18:12:28 2014 +0200 @@ -27,7 +27,8 @@ _ = unicode from copy import copy -from yams.schema import BASE_TYPES, RelationSchema, RelationDefinitionSchema +from yams.schema import (BASE_TYPES, BadSchemaDefinition, + RelationSchema, RelationDefinitionSchema) from yams import buildobjs as ybo, schema2sql as y2sql, convert_default_value from logilab.common.decorators import clear_cache @@ -407,12 +408,19 @@ description=entity.description, cardinality=entity.cardinality, constraints=get_constraints(self.cnx, entity), order=entity.ordernum, eid=entity.eid, **kwargs) - self.cnx.vreg.schema.add_relation_def(rdefdef) + try: + self.cnx.vreg.schema.add_relation_def(rdefdef) + except BadSchemaDefinition: + # rdef has been infered then explicitly added (current consensus is + # not clear at all versus infered relation handling (and much + # probably buggy) + rdef = self.cnx.vreg.schema.rschema(rdefdef.name).rdefs[rdefdef.subject, rdefdef.object] + assert rdef.infered self.cnx.execute('SET X ordernum Y+1 ' - 'WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, ' - 'X ordernum >= %(order)s, NOT X eid %(x)s', - {'x': entity.eid, 'se': fromentity.eid, - 'order': entity.ordernum or 0}) + 'WHERE X from_entity SE, SE eid %(se)s, X ordernum Y, ' + 'X ordernum >= %(order)s, NOT X eid %(x)s', + {'x': entity.eid, 'se': fromentity.eid, + 'order': entity.ordernum or 0}) return rdefdef def precommit_event(self):