Skip to content

Commit 1930ba7

Browse files
committed
add info about non-retryable constraint to string matching
Signed-off-by: Filinto Duran <[email protected]>
1 parent 7321905 commit 1930ba7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,41 @@ def my_activity(ctx: task.ActivityContext, input):
182182

183183
Even with a retry policy configured, `NonRetryableError` will fail immediately without retrying.
184184

185+
#### Error type matching behavior
186+
187+
**Important:** Error type matching uses **exact class name comparison**, not `isinstance()` checks. This is because exception objects are serialized to gRPC protobuf messages, where only the class name (as a string) survives serialization.
188+
189+
**Key implications:**
190+
191+
- **Not inheritance-aware**: If you specify `ValueError` in `non_retryable_error_types`, it will only match exceptions with the exact class name `"ValueError"`. A custom subclass like `CustomValueError(ValueError)` will NOT match.
192+
- **Workaround**: List all exception types explicitly, including subclasses you want to handle.
193+
- **Built-in exception**: `NonRetryableError` is always treated as non-retryable, matched by the name `"NonRetryableError"`.
194+
195+
**Example:**
196+
197+
```python
198+
from datetime import timedelta
199+
from durabletask import task
200+
201+
# Custom exception hierarchy
202+
class ValidationError(ValueError):
203+
pass
204+
205+
# This policy ONLY matches exact "ValueError" by name
206+
retry_policy = task.RetryPolicy(
207+
first_retry_interval=timedelta(seconds=1),
208+
max_number_of_attempts=3,
209+
non_retryable_error_types=[ValueError] # Won't match ValidationError subclass!
210+
)
211+
212+
# To handle both, list them explicitly:
213+
retry_policy = task.RetryPolicy(
214+
first_retry_interval=timedelta(seconds=1),
215+
max_number_of_attempts=3,
216+
non_retryable_error_types=[ValueError, ValidationError] # Both converted to name strings
217+
)
218+
```
219+
185220
## Getting Started
186221

187222
### Prerequisites

0 commit comments

Comments
 (0)