You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Edit content 1 and fill in the relatedItems field with content 2
Delete content 2
See content 1 serialization
relatedItems will be: [ None ]
This doesn't make sense to me. In the example, I think it's better to return an empty list. However, to do this, we would have to test the type of each element in a list here, to know if the value is a RelationValue. Or create a new adapter for the IRelationList field
Or should you handle this in the frontend?
The text was updated successfully, but these errors were encountered:
Good catch!
The serializers of a RelationList field and RelationChoice field should return only non broken RelationValues.
I suggest the following:
@adapter(IRelationList, IDexterityContent, Interface)
@implementer(IFieldSerializer)
class RelationListFieldSerializer(DefaultFieldSerializer):
def get_value(self, default=None):
"""Return field value reduced to list of non-broken Relationvalues.
Args:
default (list, optional): Default field value. Defaults to None.
Returns:
list: List of RelationValues
"""
value = getattr(
self.field.interface(self.context), self.field.__name__, default
)
return [el for el in value if el.to_object]
And accordingly for RelationChoiceFieldSerializer.
Steps to reproduce
relatedItems
field with content 2relatedItems
will be:[ None ]
This doesn't make sense to me. In the example, I think it's better to return an empty list. However, to do this, we would have to test the type of each element in a list here, to know if the value is a
RelationValue
. Or create a new adapter for theIRelationList
fieldOr should you handle this in the frontend?
The text was updated successfully, but these errors were encountered: