Skip to content

Commit

Permalink
fix(converter): handle serialization of recursive exceptions
Browse files Browse the repository at this point in the history
It is kind of an easy mistake to do in python:

```
try:
    raise ValueError("test")
except Exception as e:
    raise e from e
```

The reraised exception will have e.__cause__ referencing itself resulting in failure to serialize error and python sdk won't report anything resulting in retries and startToClose timeouts.
  • Loading branch information
yunmanger1 authored and German Ilin committed Dec 3, 2024
1 parent a90f6d4 commit 1ec3f62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion temporalio/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ def to_failure(
str(exception), type=exception.__class__.__name__
)
failure_error.__traceback__ = exception.__traceback__
failure_error.__cause__ = exception.__cause__
if exception.__cause__ and exception.__cause__ != exception:
failure_error.__cause__ = exception.__cause__
self._error_to_failure(failure_error, payload_converter, failure)
# Encode common attributes if requested
if self._encode_common_attributes:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,20 @@ async def decode(self, payloads: Sequence[Payload]) -> List[Payload]:
return list(wrapper.payloads)


async def test_broken_exception_serialization():
conv = DataConverter(
payload_codec=SimpleCodec(),
)
try:
try:
raise ValueError("test")
except Exception as e:
raise e from e
except Exception as e:
failure = Failure()
conv.failure_converter.to_failure(e, conv.payload_converter, failure)


async def test_failure_encoded_attributes():
try:
raise ApplicationError("some message", "some detail")
Expand Down

0 comments on commit 1ec3f62

Please sign in to comment.