Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Exception chain lost when retry mechanism re-raises non-retryable errors #880

Open
Assignees
ohmayr
@fernandocorreia-galileo

Description

Environment details

Description

The retry mechanism clears the__cause__ attribute when re-raising non-retryable exceptions, breaking explicit exception chaining created withraise ... from ....

Steps to reproduce

  1. Use the@retry_async.AsyncRetry decorator
  2. Raise a non-retryable exception with a cause
  3. Catch the exception and try to read or log its cause

Code example

importasynciofromgoogle.api_coreimportretry_async,exceptions@retry_async.AsyncRetry(predicate=retry_async.if_exception_type(exceptions.InternalServerError))asyncdefexample():try:raiseexceptions.Unauthenticated("Invalid credentials")exceptexceptions.Unauthenticatedasexc:raiseValueError("Access denied")fromexc# Explicit chainingasyncdefmain():# After going through retry:try:awaitexample()exceptValueErrorase:print(e.__cause__)# Expected: "401 Invalid credentials"; Actual: Noneif__name__=="__main__":asyncio.run(main())

Seehttps://github.com/googleapis/python-api-core/pull/879/changes for a unit test that fails with the current code and passes with the proposed fix.

Root Cause

Inretry_base.py:168,_default_exception_factory() returns(exc_list[-1], None), which causes raisefinal_exc fromNone on line 214, explicitly clearing__cause__.

Proposed fix

Preserve the exception'scause attribute:

# Beforereturnexc_list[-1],None# Afterfinal_exc=exc_list[-1]cause=getattr(final_exc,'__cause__',None)returnfinal_exc,cause

This maintains exception chains for better debugging and meets developer expectations for exception handling.

Draft pull request

#879

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp