Skip to content

Follow implicit exception chains (__context__) in retry_if_exception_cause_type - #713

Open
Str0k wants to merge 1 commit into
jd:mainfrom
Str0k:githubpower/t_b0a5f4f2
Open

Str0k wants to merge 1 commit into
jd:mainfrom
Str0k:githubpower/t_b0a5f4f2

Conversation

@Str0k

@Str0k Str0k commented Sep 12, 2026

Copy link
Copy Markdown

When an exception is raised inside an except block without an explicit raise ... from ..., Python stores the in-flight exception in context and leaves cause as None. retry_if_exception_cause_type only inspected cause, so such implicitly chained exceptions were never retried even when the underlying cause type matched, even though tracebacks render the chain ("During handling of the above exception, another exception occurred"). The predicate now falls back to context when no explicit cause is set and the context was not suppressed with raise ... from None, so both spellings behave identically.

Users writing except SomeError: raise WrapperError(...) (no from) reasonably expect retry_if_exception_cause_type(SomeError) to keep retrying, exactly as the explicit from SomeError form does. The implicit form is the more common spelling in application code, so the predicate silently skipped retries in exactly those cases. Related to issue #625 (retry_unless_exception_cause_type feature request): an inverted predicate would inherit this same gap, so fixing the cause-chain traversal in the existing class grounds both.

Validation: a new regression test fails on the unchanged base and passes with this patch; reproduced in an independent clean checkout.

Full-suite results (including pre-existing failures, if any):

{
  "base": {
    "exit": 1,
    "tests": 203,
    "failures": 1,
    "errors": 0,
    "skipped": 0,
    "failed_cases": [
      "tests.test_retry_if_exception_cause_type_context.test_implicit_context_chain_is_retried"
    ]
  },
  "patch": {
    "exit": 0,
    "tests": 203,
    "failures": 0,
    "errors": 0,
    "skipped": 0,
    "failed_cases": []
  }
}

AI assistance: implementation and review used Hermes with self-hosted GLM 5.3. Automated test evidence was checked separately. This does not represent a human review.

Additional checks were reproduced on fresh base and patched checkouts:

Check Base Patch
mypy 0 diagnostics 0 diagnostics
ruff 0 diagnostics 0 diagnostics
ruff_format exit 0 exit 0
docs_doctest exit 0 exit 0
docs_html exit 0 exit 0

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant