From 9a1e85a3a7bf7437acdc972fe5794e205a06b3cc Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 8 Jun 2022 11:43:01 +0200 Subject: [PATCH] communities: prevent errors in type field type attribute now checks if the value passed is a dict to prevent errors from happening before the value is validated. Now returns a normal validation error if the wrong type of value is passed. --- invenio_communities/communities/schema.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/invenio_communities/communities/schema.py b/invenio_communities/communities/schema.py index 606637221..db4cd201e 100644 --- a/invenio_communities/communities/schema.py +++ b/invenio_communities/communities/schema.py @@ -88,9 +88,11 @@ def clean(self, data, **kwargs): Why: We want to allow the output of a Schema dump, to be a valid input to a Schema load without causing strange issues. """ - for name, field in self.fields.items(): - if field.dump_only: - data.pop(name, None) + value_is_dict = isinstance(data, dict) + if value_is_dict: + for name, field in self.fields.items(): + if field.dump_only: + data.pop(name, None) return data