Skip to content

Commit

Permalink
Do not change request during serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Nov 20, 2024
1 parent 96d60bf commit ff89d12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plone/restapi/serializer/relationfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@implementer(IJsonCompatible)
def relationvalue_converter(value):
if value.to_object:
request = getRequest()
request = getRequest().clone()
request.form["metadata_fields"] = ["UID"]
summary = getMultiAdapter((value.to_object, request), ISerializeToJsonSummary)()
return json_compatible(summary)
Expand Down
13 changes: 13 additions & 0 deletions src/plone/restapi/tests/test_dxfield_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ def test_relationlist_field_serialization_returns_list(self):
value,
)

def test_relation_field_serialization_do_not_change_request(self):
self.request.form["metadata_fields"] = ["foo", "bar"]
doc2 = self.portal[
self.portal.invokeFactory(
"DXTestDocument",
id="doc2",
title="Referenceable Document",
description="Description 2",
)
]
self.serialize("test_relationchoice_field", doc2)
self.assertEqual(self.request.form["metadata_fields"], ["foo", "bar"])

def test_remoteurl_field_in_links_get_converted(self):
link = self.portal[
self.portal.invokeFactory(
Expand Down

0 comments on commit ff89d12

Please sign in to comment.