From cd12376ff835e6fea02e6b36b4503eafe1750c4c Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Thu, 6 Jun 2024 17:48:29 +0200 Subject: [PATCH] Fix error on personal-information page when you leave an existing portrait unchanged. The previous release added validation, but this caused a regression. Fixes https://github.com/plone/plone.app.users/issues/126 --- news/126.bugfix | 3 +++ plone/app/users/browser/account.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 news/126.bugfix diff --git a/news/126.bugfix b/news/126.bugfix new file mode 100644 index 00000000..aeba0c57 --- /dev/null +++ b/news/126.bugfix @@ -0,0 +1,3 @@ +Fix error on personal-information page when you leave an existing portrait unchanged. +The previous release added validation, but this caused a regression. +[maurits] diff --git a/plone/app/users/browser/account.py b/plone/app/users/browser/account.py index 720e53f9..b9aa9fde 100644 --- a/plone/app/users/browser/account.py +++ b/plone/app/users/browser/account.py @@ -21,6 +21,7 @@ from Products.statusmessages.interfaces import IStatusMessage from z3c.form import button from z3c.form import form +from z3c.form.interfaces import NOT_CHANGED from zope import schema from zope.cachedescriptors.property import Lazy as lazy_property from zope.component import getMultiAdapter @@ -272,8 +273,12 @@ def validate_portrait(self, action, data): SVG files are not yet supported. """ error_keys = [error.field.getName() for error in action.form.widgets.errors] - if "portrait" not in error_keys and data["portrait"] is not None: - portrait = data["portrait"].open() + if "portrait" in error_keys: + return + portrait_file = data["portrait"] + if portrait_file is None or portrait_file is NOT_CHANGED: + return + with portrait_file.open() as portrait: try: Image.open(portrait) except UnidentifiedImageError: