Skip to content

Python: fix: prevent inner_exception from being lost in AgentFrameworkException#5167

Open
Bahtya wants to merge 1 commit intomicrosoft:mainfrom
Bahtya:fix/exception-inner-exception-lost
Open

Python: fix: prevent inner_exception from being lost in AgentFrameworkException#5167
Bahtya wants to merge 1 commit intomicrosoft:mainfrom
Bahtya:fix/exception-inner-exception-lost

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 8, 2026

Problem

AgentFrameworkException.__init__() unconditionally calls super().__init__(message, *args) after the conditional super().__init__(message, inner_exception, *args). When inner_exception is provided, the second call overwrites the exception args, losing the inner exception reference.

Root Cause

Missing else branch — both super().__init__() calls execute when inner_exception is truthy.

Fix

Add else: branch so super().__init__() is called exactly once with the correct arguments.

Before:

if inner_exception:
    super().__init__(message, inner_exception, *args)
super().__init__(message, *args)  # always runs, overwrites args

After:

if inner_exception:
    super().__init__(message, inner_exception, *args)
else:
    super().__init__(message, *args)

Fixes #5155

The __init__ method unconditionally called super().__init__() after
the conditional call with inner_exception, effectively overwriting the
exception args and losing the inner_exception reference.

Add else branch so super().__init__() is only called once with the
correct arguments.

Fixes microsoft#5155

Signed-off-by: bahtya <bahtyar153@qq.com>
@moonbox3 moonbox3 added the python label Apr 8, 2026
@github-actions github-actions bot changed the title fix: prevent inner_exception from being lost in AgentFrameworkException Python: fix: prevent inner_exception from being lost in AgentFrameworkException Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: "inner_exception" Information will be lost.

3 participants