[migration] don't crash when deleting a non-existing rtype
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 22 Dec 2014 14:39:50 +0100
changeset 10129 52adf66fae7d
parent 10128 894957e1ce2d
child 10130 ae518e501179
[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.
server/migractions.py
server/test/unittest_migractions.py
--- 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):