# HG changeset patch # User Sylvain Thénault # Date 1440493894 -7200 # Node ID d89e9176d263c5fca13d8f46dc5e07f604faff79 # Parent 1ab79c435fae9cd385413569b4ad018549b9e4ba [migration] don't attempt to carry over values when renaming a computed relation Without the fix in migractions.py, the introduced test crashes with an operational error because of an attempt to write to a non-existing relation table (computed relations are not materialized). Closes #6304946 diff -r 1ab79c435fae -r d89e9176d263 server/migractions.py --- a/server/migractions.py Fri Aug 21 11:01:08 2015 +0200 +++ b/server/migractions.py Tue Aug 25 11:11:34 2015 +0200 @@ -1085,8 +1085,9 @@ default='n'): raise SystemExit(1) self.cmd_add_relation_type(newname, commit=True) - self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname), - ask_confirm=self.verbosity>=2) + if not self.repo.schema[oldname].rule: + self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname), + ask_confirm=self.verbosity>=2) self.cmd_drop_relation_type(oldname, commit=commit) def cmd_add_relation_definition(self, subjtype, rtype, objtype, commit=True): diff -r 1ab79c435fae -r d89e9176d263 server/test/datacomputed/migratedapp/schema.py --- a/server/test/datacomputed/migratedapp/schema.py Fri Aug 21 11:01:08 2015 +0200 +++ b/server/test/datacomputed/migratedapp/schema.py Tue Aug 25 11:11:34 2015 +0200 @@ -55,3 +55,7 @@ class whatever(ComputedRelation): rule = 'S employees E, O associates E' + + +class renamed(ComputedRelation): + rule = 'S employees E, O concerns E' diff -r 1ab79c435fae -r d89e9176d263 server/test/datacomputed/schema.py --- a/server/test/datacomputed/schema.py Fri Aug 21 11:01:08 2015 +0200 +++ b/server/test/datacomputed/schema.py Tue Aug 25 11:11:34 2015 +0200 @@ -52,3 +52,7 @@ class whatever(ComputedRelation): rule = 'S employees E, O concerns E' + + +class to_be_renamed(ComputedRelation): + rule = 'S employees E, O concerns E' diff -r 1ab79c435fae -r d89e9176d263 server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Fri Aug 21 11:01:08 2015 +0200 +++ b/server/test/unittest_migractions.py Tue Aug 25 11:11:34 2015 +0200 @@ -763,6 +763,12 @@ 'Cannot synchronize a relation definition for a computed ' 'relation (whatever)') + def test_computed_relation_rename_relation_type(self): + with self.mh() as (cnx, mh): + mh.cmd_rename_relation_type('to_be_renamed', 'renamed') + self.assertIn('renamed', self.schema) + self.assertNotIn('to_be_renamed', self.schema) + # computed attributes migration ############################################ def setup_add_score(self):