[entity] fix crash when using cw_instantiate with empty related entity list; closes #2094462 stable
authorFlorent Cayré <florent.cayre@gmail.com>
Wed, 08 Feb 2012 14:22:48 +0100
branchstable
changeset 8199 fb5c0e60a615
parent 8198 ce9c6ae03c2d
child 8200 182d47d87a5c
[entity] fix crash when using cw_instantiate with empty related entity list; closes #2094462
entity.py
test/unittest_entity.py
--- a/entity.py	Wed Feb 08 14:17:09 2012 +0100
+++ b/entity.py	Wed Feb 08 14:22:48 2012 +0100
@@ -481,7 +481,9 @@
             assert eschema.has_relation(attr, role), '%s %s not found on %s' % (attr, role, eschema)
             rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr]
             if not rschema.final and isinstance(value, (tuple, list, set, frozenset)):
-                if len(value) == 1:
+                if len(value) == 0:
+                    continue # avoid crash with empty IN clause
+                elif len(value) == 1:
                     value = iter(value).next()
                 else:
                     # prepare IN clause
--- a/test/unittest_entity.py	Wed Feb 08 14:17:09 2012 +0100
+++ b/test/unittest_entity.py	Wed Feb 08 14:22:48 2012 +0100
@@ -143,6 +143,8 @@
         req = self.request()
         p1 = req.create_entity('Personne', nom=u'di')
         p2 = req.create_entity('Personne', nom=u'mascio')
+        t = req.create_entity('Tag', name=u't0', tags=[])
+        self.assertItemsEqual(t.tags, [])
         t = req.create_entity('Tag', name=u't1', tags=p1)
         self.assertItemsEqual(t.tags, [p1])
         t = req.create_entity('Tag', name=u't2', tags=p1.eid)