Commit a6a5b6f
authored
fix: preserve exception cause (#879)
Fixes #880
## Problem:
When the retry mechanism re-raises non-retryable exceptions, it
explicitly clears the exception chain by using raise final_exc from
None. This breaks explicit exception chaining created with raise ...
from ..., making the original cause (__cause__) inaccessible for
debugging.
## Fix:
Modified `_default_exception_factory()` in `retry_base.py` to preserve
the `__cause__` attribute when re-raising non-retryable exceptions.
Instead of returning `(exc_list[-1], None)`, we now return
`(exc_list[-1], getattr(exc_list[-1], '__cause__', None))`.
This ensures that exception chains are maintained through the retry
mechanism, preserving debugging information and meeting developer
expectations for exception handling.
## Testing:
Added a new test case in `tests/unit/retry/test_retry_base.py` that
checks that the cause from the chained exception is preserved by
`build_retry_error`.1 parent 2210c3f commit a6a5b6f
File tree
2 files changed
+24
-2
lines changed- google/api_core/retry
- tests/unit/retry
2 files changed
+24
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
77 | 97 | | |
78 | 98 | | |
79 | 99 | | |
| |||
0 commit comments