[integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Sep 2010 23:23:16 +0200
branchstable
changeset 6188 e1c9610b2360
parent 6187 348c7d93cda3
child 6189 9fa02f352c8c
[integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
server/repository.py
server/test/unittest_repository.py
--- a/server/repository.py	Tue Sep 07 23:02:08 2010 +0200
+++ b/server/repository.py	Tue Sep 07 23:23:16 2010 +0200
@@ -1083,6 +1083,7 @@
         # set inline relation cache before call to after_add_entity
         for attr, value in relations:
             session.update_rel_cache_add(entity.eid, attr, value)
+            del_existing_rel_if_needed(session, entity.eid, attr, value)
         # trigger after_add_entity after after_add_relation
         if source.should_call_hooks:
             self.hm.call_hooks('after_add_entity', session, entity=entity)
--- a/server/test/unittest_repository.py	Tue Sep 07 23:02:08 2010 +0200
+++ b/server/test/unittest_repository.py	Tue Sep 07 23:23:16 2010 +0200
@@ -385,6 +385,13 @@
         self.assertEquals(len(rset), 1)
         self.assertEquals(rset.rows[0][0], p2.eid)
 
+    def test_delete_if_object_inlined_singlecard(self):
+        req = self.request()
+        c = req.create_entity('Card', title=u'Carte')
+        req.create_entity('Personne', nom=u'Vincent', fiche=c)
+        req.create_entity('Personne', nom=u'Florent', fiche=c)
+        self.commit()
+        self.assertEquals(len(c.reverse_fiche), 1)
 
     def test_set_attributes_in_before_update(self):
         # local hook