Skip to content

fix(client): guard against AttributeError in AsyncHttpxClientWrapper.…#2963

Open
raulblazquezbullon wants to merge 1 commit intoopenai:mainfrom
raulblazquezbullon:fix/async-client-del-attribute-error
Open

fix(client): guard against AttributeError in AsyncHttpxClientWrapper.…#2963
raulblazquezbullon wants to merge 1 commit intoopenai:mainfrom
raulblazquezbullon:fix/async-client-del-attribute-error

Conversation

@raulblazquezbullon
Copy link

@raulblazquezbullon raulblazquezbullon commented Mar 12, 2026

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Move the is_closed guard inside the try/except block in AsyncHttpxClientWrapper.__del__.

If the object was partially initialized (an exception was raised inside httpx.BaseClient.__init__ before self._state was assigned), the garbage collector triggers __del__ on an object that has no _state attribute. The is_closed property accesses _state, so it raises AttributeError, which propagates as an unsilenced "Exception ignored" warning.

Observed traceback:

Exception ignored in: <function AsyncHttpxClientWrapper.del at 0x106384ae0>
Traceback (most recent call last):
File ".../openai/_base_client.py", line 1430, in __del__
    if self.is_closed:
    ^^^^^^^^^^^^^^
File ".../httpx/_client.py", line 202, in is_closed
    return self._state == ClientState.CLOSED
    ^^^^^^^^^^^
AttributeError: 'AsyncHttpxClientWrapper' object has no attribute '_state'

The fix moves the check inside the existing try/except Exception, consistent with the method's original intent to silence all finalization errors. No functional behaviour changes for fully initialized objects.

Additional context & links

  • httpx.BaseClient.__init__ assigns _state as its last statement, any earlier failure (e.g. invalid base_url, bad headers) leaves _state unset.
  • The fix is purely defensive and introduces no new public API surface.

@raulblazquezbullon raulblazquezbullon requested a review from a team as a code owner March 12, 2026 17:33
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