diff --git a/news/1851.bugfix b/news/1851.bugfix new file mode 100644 index 000000000..36f1da159 --- /dev/null +++ b/news/1851.bugfix @@ -0,0 +1,2 @@ +Make primary field target adapter return early. +[maurits] diff --git a/src/plone/restapi/serializer/dxcontent.py b/src/plone/restapi/serializer/dxcontent.py index e497bb6b6..9e793dc97 100644 --- a/src/plone/restapi/serializer/dxcontent.py +++ b/src/plone/restapi/serializer/dxcontent.py @@ -220,23 +220,24 @@ def __init__(self, context, request): def __call__(self): primary_field_name = self.get_primary_field_name() + if not primary_field_name: + return for schema in iterSchemata(self.context): read_permissions = mergedTaggedValueDict(schema, READ_PERMISSIONS_KEY) for name, field in getFields(schema).items(): - if not self.check_permission(read_permissions.get(name), self.context): - continue - if name != primary_field_name: continue + if not self.check_permission(read_permissions.get(name), self.context): + return + target_adapter = queryMultiAdapter( (field, self.context, self.request), IPrimaryFieldTarget ) - if target_adapter: - target = target_adapter() - if target: - return target + if not target_adapter: + return + return target_adapter() def get_primary_field_name(self): fieldname = None