# HG changeset patch # User Sylvain Thénault # Date 1254319543 -7200 # Node ID dfb2ebb765e248faa1a8f6f382b1ccfaafc27af1 # Parent 2dc3908f667f0ef092fa718c8bfd0064cbe2d909 [migration] fix addition of attribute to a parent class diff -r 2dc3908f667f -r dfb2ebb765e2 server/schemahooks.py --- a/server/schemahooks.py Tue Sep 29 15:10:12 2009 -0700 +++ b/server/schemahooks.py Wed Sep 30 16:05:43 2009 +0200 @@ -307,10 +307,11 @@ default = entity.defaultval if default is not None: default = TYPE_CONVERTER[entity.otype.name](default) - rdef = self.init_rdef(default=default, - indexed=entity.indexed, - fulltextindexed=entity.fulltextindexed, - internationalizable=entity.internationalizable) + props = {'default': default, + 'indexed': entity.indexed, + 'fulltextindexed': entity.fulltextindexed, + 'internationalizable': entity.internationalizable} + rdef = self.init_rdef(**props) sysource = session.pool.source('system') attrtype = type_from_constraints(sysource.dbhelper, rdef.object, rdef.constraints) @@ -343,6 +344,20 @@ except Exception, ex: self.error('error while creating index for %s.%s: %s', table, column, ex) + # final relations are not infered, propagate + rschema = self.schema.rschema(rdef.name) + eschema = self.schema.eschema(rdef.subject) + props.update({'constraints': rdef.constraints, + 'description': rdef.description, + 'cardinality': rdef.cardinality, + 'constraints': rdef.constraints, + 'order': rdef.order}) + for specialization in eschema.specialized_by(False): + if rschema.has_rdef(specialization, rdef.object): + continue + for rql, args in ss.frdef2rql(rschema, str(specialization), + rdef.object, props): + session.execute(rql, args) class SourceDbCWRelationAdd(SourceDbCWAttributeAdd): diff -r 2dc3908f667f -r dfb2ebb765e2 server/test/unittest_hooks.py --- a/server/test/unittest_hooks.py Tue Sep 29 15:10:12 2009 -0700 +++ b/server/test/unittest_hooks.py Wed Sep 30 16:05:43 2009 +0200 @@ -502,5 +502,15 @@ 'RT name "prenom", E name "Personne"') self.commit() + + def test_add_attribute_to_base_class(self): + self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval "noname", X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F ' + 'WHERE RT name "nom", E name "BaseTransition", F name "String"') + self.commit() + self.schema.rebuild_infered_relations() + self.failUnless('Transition' in self.schema['nom'].subjects()) + self.failUnless('WorkflowTransition' in self.schema['nom'].subjects()) + self.execute('Any X WHERE X is_instance_of BaseTransition, X nom "hop"') + if __name__ == '__main__': unittest_main()