Skip to content

Commit

Permalink
Prevent "Saved data" view from raising an exception if a field is not…
Browse files Browse the repository at this point in the history
… found. fixes gh-381
  • Loading branch information
frapell committed Nov 24, 2022
1 parent c2f843d commit c39970a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Empty file added news/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions news/381.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent "Saved data" view from raising an exception if a field is not found
[frapell]
15 changes: 14 additions & 1 deletion src/collective/easyform/browser/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.schema import getFieldsInOrder
from ZPublisher.BaseRequest import DefaultPublishTraverse
import logging


logger = logging.getLogger(__name__)
PMF = MessageFactory("plone")


Expand Down Expand Up @@ -141,7 +143,18 @@ def update_schema(self):
fields = field.Fields(self.get_schema)
showFields = getattr(self.field, "showFields", [])
if showFields:
fields = fields.select(*showFields)
# showFields is a fixed list of field ids, and if those ids are no
# longer there, you get an exception, so first filter them.
existingFields = []
for fid in showFields:
if fid not in fields:
logger.warning(
"Field '%s' is no longer present in the form %s. Ignoring." %
(fid, '/'.join(self.context.getPhysicalPath()))
)
else:
existingFields.append(fid)
fields = fields.select(*existingFields)
return fields

@property
Expand Down

0 comments on commit c39970a

Please sign in to comment.