[integrity] fix case where we can get two entities related while the cardinality is single on the object of an inlined relation
--- 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