From c39970a0dd346e1d2ef2cb86b51d389e188ab58d Mon Sep 17 00:00:00 2001 From: Franco Pellegrini Date: Thu, 24 Nov 2022 14:31:16 -0300 Subject: [PATCH] Prevent "Saved data" view from raising an exception if a field is not found. fixes gh-381 --- news/.gitkeep | 0 news/381.bugfix | 2 ++ src/collective/easyform/browser/actions.py | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 news/.gitkeep create mode 100644 news/381.bugfix diff --git a/news/.gitkeep b/news/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/news/381.bugfix b/news/381.bugfix new file mode 100644 index 00000000..d1422b7e --- /dev/null +++ b/news/381.bugfix @@ -0,0 +1,2 @@ +Prevent "Saved data" view from raising an exception if a field is not found +[frapell] diff --git a/src/collective/easyform/browser/actions.py b/src/collective/easyform/browser/actions.py index 3b78c485..74e73e89 100644 --- a/src/collective/easyform/browser/actions.py +++ b/src/collective/easyform/browser/actions.py @@ -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") @@ -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