Got "unhashable type list" while creating entity with inlinded relation
With cubicweb 3.25.4, I declared the following my cube's schema:
class HorizonDecomposition(EntityType):
[...] # Basic stuff
name = String(required=True, unique=True, maxsize=64, fulltextindexed=True,
indexed=True)
class HorizonDecompositionSection(EntityType):
[...] # Basic stuff
hd_section_of = SubjectRelation('HorizonDecomposition',
cardinality='1+',
composite='object',
inlined=True)
Now from the web interface, when I try to create a HorizonDecomposition with one HorizonDecompositionSection (required by cardinality), I get the following issue:
2018-09-24 10:42:02 - (cubicweb.web) ERROR: unexpected error while validating form
Traceback (most recent call last):
File "/venv/local/lib/python2.7/site-packages/cubicweb/web/views/basecontrollers.py", line 209, in _validate_form
ctrl.publish(None)
File "/venv/local/lib/python2.7/site-packages/cubicweb/web/views/editcontroller.py", line 132, in publish
self._default_publish()
File "/venv/local/lib/python2.7/site-packages/cubicweb/web/views/editcontroller.py", line 198, in _default_publish
for formparams in self._ordered_formparams():
File "/venv/local/lib/python2.7/site-packages/cubicweb/web/views/editcontroller.py", line 169, in _ordered_formparams
if target_eid in values_by_eid:
TypeError: unhashable type: 'list'
Also, the part of the creation form that concerns HorizonDecompositionSection shows a selector for "hd_section_of". This should not be as its value will be the HorizonDecomposition that I am currently creating.
Anyway, the following patch in cubicweb avoids the Traceback, but not the view:
diff -r b8567725c473 cubicweb/web/views/editcontroller.py
--- a/cubicweb/web/views/editcontroller.py Fri Jan 12 10:48:34 2018 +0100
+++ b/cubicweb/web/views/editcontroller.py Fri Sep 28 11:29:20 2018 +0200
@@ -166,13 +166,13 @@
# use .get since param may be unspecified (though it will usually lead
# to a validation error later)
target_eid = values.get(param)
- if target_eid in values_by_eid:
+ if target_eid is not None and target_eid[0] in values_by_eid:
# add dependency from the target entity to the
# current one
if role == 'object':
- graph.setdefault(target_eid, set()).add(eid)
+ graph.setdefault(target_eid[0], set()).add(eid)
else:
- graph.setdefault(eid, set()).add(target_eid)
+ graph.setdefault(eid, set()).add(target_eid[0])
break
for eid in reversed(ordered_nodes(graph)):
yield values_by_eid[eid]{code}
Is this code correct ? Can you integrate it asap so my users will not be blocked anymore ?
original ticket : https://www.cubicweb.org/ticket/17169126