Commit e95ab326 authored by Aurelien Campeas's avatar Aurelien Campeas
Browse files

[entity,views/json] backout 353bbd17a8b6 (reopens #2559931)

Calling .complete() unconditionnally from the json encoder is unsafe
since on entity creation validation:

* an eid may have been drawn (hence even .has_eid() would not help)
  while processing form data in the edit controller

* a ValidationError may have been raised and the entity-creating
  transaction rollbacked

This leads to a crash on the return path from the validation to the
browser, where the json_dumps((status, args, entity)) call will
stumble upon the .complete() call which will fail because the entity
does not (any more) exist in the database.

branch : stable
parent 9bb93efa1952
......@@ -539,10 +539,8 @@ class Entity(AppObject):
"""custom json dumps hook to dump the entity's eid
which is not part of dict structure itself
dumpable = self.cw_attr_cache.copy()
dumpable['eid'] = self.eid
dumpable['__cwetype__'] = self.__regid__
return dumpable
def cw_adapt_to(self, interface):
......@@ -111,7 +111,12 @@ class JsonEntityView(JsonMixIn, EntityView):
title = _('json-entities-export-view')
def call(self):
if self.cw_rset is None:
entities = []
for entity in self.cw_rset.entities():
entity.complete() # fetch all attributes
# hack to add extra metadata
'__cwetype__': entity.__regid__,
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