[migration] don't crash when deleting a non-existing rtype
When asked to delete a relation type, instead of checking if it was
computed or not, just delete both the CWRType and CWComputedRType.
--- a/server/migractions.py Fri Dec 19 12:39:42 2014 +0100
+++ b/server/migractions.py Mon Dec 22 14:39:50 2014 +0100
@@ -1061,12 +1061,9 @@
def cmd_drop_relation_type(self, rtype, commit=True):
"""unregister an existing relation type"""
- rschema = self.repo.schema[rtype]
- if rschema.rule:
- etype = 'CWComputedRType'
- else:
- etype = 'CWRType'
- self.rqlexec('DELETE %s X WHERE X name %r' % (etype, rtype),
+ self.rqlexec('DELETE CWRType X WHERE X name %r' % rtype,
+ ask_confirm=self.verbosity>=2)
+ self.rqlexec('DELETE CWComputedRType X WHERE X name %r' % rtype,
ask_confirm=self.verbosity>=2)
if commit:
self.commit()
--- a/server/test/unittest_migractions.py Fri Dec 19 12:39:42 2014 +0100
+++ b/server/test/unittest_migractions.py Mon Dec 22 14:39:50 2014 +0100
@@ -309,6 +309,8 @@
self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',))
mh.cmd_drop_relation_type('filed_under2')
self.assertNotIn('filed_under2', self.schema)
+ # this should not crash
+ mh.cmd_drop_relation_type('filed_under2')
def test_add_relation_definition_nortype(self):
with self.mh() as (cnx, mh):