1919from temporalio .api .failure .v1 import Failure
2020from temporalio .client import Client , WorkflowUpdateFailedError
2121from temporalio .common import RetryPolicy
22+ from temporalio .contrib .pydantic import PydanticJSONPlainPayloadConverter
2223from temporalio .converter import (
2324 ActivitySerializationContext ,
2425 CompositePayloadConverter ,
2526 DataConverter ,
26- DefaultPayloadConverter ,
2727 DefaultFailureConverter ,
28+ DefaultPayloadConverter ,
2829 EncodingPayloadConverter ,
2930 JSONPlainPayloadConverter ,
3031 PayloadCodec ,
3334 WithSerializationContext ,
3435 WorkflowSerializationContext ,
3536)
36- from temporalio .contrib .pydantic import PydanticJSONPlainPayloadConverter
37- from temporalio .exceptions import ApplicationError , ActivityError
37+ from temporalio .exceptions import ActivityError , ApplicationError
3838from temporalio .worker import Worker
3939from temporalio .worker ._workflow_instance import UnsandboxedWorkflowRunner
4040
@@ -975,8 +975,6 @@ def get_caller_location() -> list[str]:
975975 return result
976976
977977
978-
979-
980978@activity .defn
981979async def failing_activity () -> TraceData :
982980 raise ApplicationError ("test error" , TraceData ())
@@ -1003,13 +1001,18 @@ def __init__(self):
10031001 super ().__init__ (encode_common_attributes = False )
10041002 self .context : Optional [SerializationContext ] = None
10051003
1006- def with_context (self , context : Optional [SerializationContext ]) -> "ContextFailureConverter" :
1004+ def with_context (
1005+ self , context : Optional [SerializationContext ]
1006+ ) -> "ContextFailureConverter" :
10071007 converter = ContextFailureConverter ()
10081008 converter .context = context
10091009 return converter
10101010
10111011 def to_failure (
1012- self , exception : BaseException , payload_converter : PayloadConverter , failure : Failure
1012+ self ,
1013+ exception : BaseException ,
1014+ payload_converter : PayloadConverter ,
1015+ failure : Failure ,
10131016 ) -> None :
10141017 super ().to_failure (exception , payload_converter , failure )
10151018 if isinstance (exception , ApplicationError ) and exception .details :
@@ -1024,7 +1027,7 @@ def to_failure(
10241027 context = dataclasses .asdict (self .context ),
10251028 )
10261029 )
1027-
1030+
10281031 def from_failure (
10291032 self , failure : Failure , payload_converter : PayloadConverter
10301033 ) -> BaseException :
@@ -1132,12 +1135,16 @@ class PydanticData(BaseModel):
11321135 trace : List [str ] = []
11331136
11341137
1135- class ContextPydanticJSONConverter (PydanticJSONPlainPayloadConverter , WithSerializationContext ):
1138+ class ContextPydanticJSONConverter (
1139+ PydanticJSONPlainPayloadConverter , WithSerializationContext
1140+ ):
11361141 def __init__ (self ):
11371142 super ().__init__ ()
11381143 self .context : Optional [SerializationContext ] = None
11391144
1140- def with_context (self , context : Optional [SerializationContext ]) -> "ContextPydanticJSONConverter" :
1145+ def with_context (
1146+ self , context : Optional [SerializationContext ]
1147+ ) -> "ContextPydanticJSONConverter" :
11411148 converter = ContextPydanticJSONConverter ()
11421149 converter .context = context
11431150 return converter
@@ -1162,7 +1169,9 @@ def __init__(self):
11621169 )
11631170 self .context : Optional [SerializationContext ] = None
11641171
1165- def with_context (self , context : Optional [SerializationContext ]) -> "ContextPydanticConverter" :
1172+ def with_context (
1173+ self , context : Optional [SerializationContext ]
1174+ ) -> "ContextPydanticConverter" :
11661175 converter = ContextPydanticConverter ()
11671176 converter .context = context
11681177 # Also set context on all sub-converters
@@ -1187,7 +1196,7 @@ async def run(self, data: PydanticData) -> PydanticData:
11871196async def test_pydantic_converter_with_context (client : Client ):
11881197 wf_id = str (uuid .uuid4 ())
11891198 task_queue = str (uuid .uuid4 ())
1190-
1199+
11911200 test_client = Client (
11921201 client .service_client ,
11931202 namespace = client .namespace ,
0 commit comments