Skip to content

Commit

Permalink
use to_id attribute to check content's existance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Faakhir30 committed Oct 2, 2024
1 parent f87a86b commit 8c67abe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/plone/restapi/serializer/relationfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def get_value(self, default=[]):
Returns:
list: List of RelationValues
"""
value = getattr(
self.field.interface(self.context), self.field.__name__, default
)
value = super().get_value()
if not value:
return []
return [el for el in value if el.to_object]
return [el for el in value if el.to_id]
9 changes: 7 additions & 2 deletions src/plone/restapi/tests/test_dxcontent_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from zope.component import queryUtility
from zope.interface import Interface
from z3c.relationfield import RelationValue
from z3c.relationfield.event import _setRelation
from zope.component import getUtility
from zope.intid.interfaces import IIntIds
from zope.publisher.interfaces.browser import IBrowserRequest
Expand Down Expand Up @@ -201,10 +202,14 @@ def test_serializer_excludes_deleted_relations(self):
"DXTestDocument",
id="doc2",
)
rel1 = RelationValue(intids.getId(self.portal.doc1))
rel2 = RelationValue(intids.getId(self.portal.doc2))
self.portal.doc1.test_relationlist_field = [
RelationValue(intids.getId(self.portal.doc1)),
RelationValue(intids.getId(self.portal.doc2)),
rel1,
rel2,
]
_setRelation(self.portal.doc1, "test_relationlist_field", rel1)
_setRelation(self.portal.doc1, "test_relationlist_field", rel2)
# delete doc2 to make sure we have a None value in the relation list
self.portal.manage_delObjects(["doc2"])

Expand Down

0 comments on commit 8c67abe

Please sign in to comment.