@@ -1739,3 +1739,58 @@ async def test_pydantic_converter_with_context(client: Client):
17391739 task_queue = task_queue ,
17401740 )
17411741 assert f"wf_{ wf_id } " in result .trace
1742+
1743+
1744+ # Test customized DefaultPayloadConverter
1745+
1746+ # The SDK's CompositePayloadConverter comes with a with_context implementation that ensures that its
1747+ # component EncodingPayloadConverters will be replaced with the results of calling with_context() on
1748+ # them, if they support with_context (this happens when we call data_converter._with_context). Here,
1749+ # the user has subclassed DefaultPayloadConverter (which inherits from CompositePayloadConverter).
1750+ # The test confirms that the CompositePayloadConverter's with_context yields an instance of the
1751+ # user's subclass.
1752+
1753+
1754+ class UserMethodCalledError (Exception ):
1755+ pass
1756+
1757+
1758+ class CustomPayloadConverter (DefaultPayloadConverter , WithSerializationContext ):
1759+ def to_payloads (
1760+ self , values : Sequence [Any ]
1761+ ) -> List [temporalio .api .common .v1 .Payload ]:
1762+ raise UserMethodCalledError
1763+
1764+ def from_payloads (
1765+ self ,
1766+ payloads : Sequence [temporalio .api .common .v1 .Payload ],
1767+ type_hints : Optional [List [Type ]] = None ,
1768+ ) -> List [Any ]:
1769+ raise NotImplementedError
1770+
1771+
1772+ async def test_user_customization_of_default_payload_converter (
1773+ client : Client ,
1774+ ):
1775+ wf_id = str (uuid .uuid4 ())
1776+ task_queue = str (uuid .uuid4 ())
1777+
1778+ client_config = client .config ()
1779+ client_config ["data_converter" ] = dataclasses .replace (
1780+ DataConverter .default ,
1781+ payload_converter_class = CustomPayloadConverter ,
1782+ )
1783+ client = Client (** client_config )
1784+
1785+ async with Worker (
1786+ client ,
1787+ task_queue = task_queue ,
1788+ workflows = [EchoWorkflow ],
1789+ ):
1790+ with pytest .raises (UserMethodCalledError ):
1791+ await client .execute_workflow (
1792+ EchoWorkflow .run ,
1793+ TraceData (),
1794+ id = wf_id ,
1795+ task_queue = task_queue ,
1796+ )
0 commit comments