[schema migration] test reproducing pb when deleting a relation definition with mandatory card and without removing the associated rtype + fix
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 07 Aug 2009 17:42:04 +0200
changeset 2745 0dafa29ace1f
parent 2744 66048c669933
child 2746 cfcc7f6121d6
[schema migration] test reproducing pb when deleting a relation definition with mandatory card and without removing the associated rtype + fix
server/hooks.py
server/schemahooks.py
server/test/data/migratedapp/schema.py
server/test/unittest_migractions.py
--- a/server/hooks.py	Fri Aug 07 17:40:52 2009 +0200
+++ b/server/hooks.py	Fri Aug 07 17:42:04 2009 +0200
@@ -313,6 +313,9 @@
     if rtype in DONT_CHECK_RTYPES_ON_DEL:
         return
     card = rproperty(session, rtype, eidfrom, eidto, 'cardinality')
+    pendingrdefs = session.transaction_data.get('pendingrdefs', ())
+    if (session.describe(eidfrom)[0], rtype, session.describe(eidto)[0]) in pendingrdefs:
+        return
     pendingeids = session.transaction_data.get('pendingeids', ())
     if card[0] in '1+' and not eidfrom in pendingeids:
         checkrel_if_necessary(session, CheckSRelationOp, rtype, eidfrom)
--- a/server/schemahooks.py	Fri Aug 07 17:40:52 2009 +0200
+++ b/server/schemahooks.py	Fri Aug 07 17:42:04 2009 +0200
@@ -772,6 +772,8 @@
     else:
         rdeftype = 'CWRelation'
         if not (subjschema.eid in pendings or objschema.eid in pendings):
+            pending = session.transaction_data.setdefault('pendingrdefs', set())
+            pending.add((subjschema, rschema, objschema))
             session.execute('DELETE X %s Y WHERE X is %s, Y is %s'
                             % (rschema, subjschema, objschema))
     execute = session.unsafe_execute
--- a/server/test/data/migratedapp/schema.py	Fri Aug 07 17:40:52 2009 +0200
+++ b/server/test/data/migratedapp/schema.py	Fri Aug 07 17:42:04 2009 +0200
@@ -90,7 +90,7 @@
 
     travaille = SubjectRelation('Societe')
     concerne = SubjectRelation('Affaire')
-    concerne2 = SubjectRelation('Affaire')
+    concerne2 = SubjectRelation(('Affaire', 'Note'), cardinality='1*')
     connait = SubjectRelation('Personne', symetric=True)
 
 class Societe(EntityType):
--- a/server/test/unittest_migractions.py	Fri Aug 07 17:40:52 2009 +0200
+++ b/server/test/unittest_migractions.py	Fri Aug 07 17:42:04 2009 +0200
@@ -177,8 +177,19 @@
         self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire')
         self.assertEquals(self.schema['concerne2'].subjects(),
                           ('Personne',))
-        self.assertEquals(self.schema['concerne2'].objects(), ('Affaire',))
+        self.assertEquals(self.schema['concerne2'].objects(),
+                          ('Affaire', ))
+        self.assertEquals(self.schema['concerne2'].rproperty('Personne', 'Affaire', 'cardinality'),
+                          '1*')
+        self.mh.cmd_add_relation_definition('Personne', 'concerne2', 'Note')
+        self.assertEquals(sorted(self.schema['concerne2'].objects()), ['Affaire', 'Note'])
+        self.mh.add_entity('Personne', nom=u'tot')
+        self.mh.add_entity('Affaire')
+        self.mh.rqlexec('SET X concerne2 Y WHERE X is Personne, Y is Affaire')
+        self.commit()
         self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire')
+        self.failUnless('concerne2' in self.schema)
+        self.mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Note')
         self.failIf('concerne2' in self.schema)
 
     def test_drop_relation_definition_existant_rtype(self):