Commit 88ecd5f8 authored by Florent Cayré's avatar Florent Cayré
Browse files

[entity] fix crash when using cw_instantiate with empty related entity list; closes #2094462

--HG--
branch : stable
parent ce9c6ae03c2d
......@@ -481,7 +481,9 @@ class Entity(AppObject):
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
......
......@@ -143,6 +143,8 @@ class EntityTC(CubicWebTC):
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment