fix: document suppressed client cleanup errors#3436
Conversation
nomiveritas
left a comment
There was a problem hiding this comment.
@nightcityblade I am reviewing this Pull Request and cannot approve these changes as currently submitted due to structural and technical concerns regarding codebase quality:
- Redundant Logic: Adding an explicit
returnstatement at the end of anexcept Exception:block inside a Python destructor (__del__) is redundant. Python functions implicitly returnNoneupon reaching the end of their execution path. This change adds dead code without altering execution behavior. - Guidance for the Root Cause (#3428): Simply replacing
passwith a comment and a redundant return statement suppresses the exception silently without diagnosing the lifecycle issue. To properly resolve this, you should implement structured logging within the exception handler. Consider importing and utilizing the standardlogginglibrary to log the cleanup failure at aDEBUGorWARNINGlevel (e.g.,logger.debug("Failed to clear client resources during destruction: %s", e)). This ensures the exception remains non-blocking for the garbage collector while providing critical visibility into infrastructure errors.
Please refactor this PR to include proper diagnostics instead of cosmetic placeholder statements. Let's ensure the implementation meets proper engineering standards.
Respectfully Nomiveritas
|
Updated the branch to address the review: the destructor still suppresses cleanup exceptions, but now logs them at debug level so cleanup failures remain diagnosable without raising from |
nomiveritas
left a comment
There was a problem hiding this comment.
@nightcityblade Thank you for addressing the technical feedback promptly. The implementation of structured diagnostics via debug-level logging correctly balances garbage collection safety with resource visibility, resolving the redundancy identified in the initial commit.
The refactored changes now align with proper engineering standards. LGTM.
Respectfully Nomiveritas
Changes being requested
Replace empty
except Exception: passhandlers in the sync and async HTTP client wrapper destructors with explicit comments andreturnstatements. This keeps destructor cleanup failures suppressed intentionally while making the behavior clear.Fixes #3428
Additional context & links
Tests run:
ruff check src/openai/_base_client.pyruff format --check src/openai/_base_client.pygit diff --checkpytest tests/test_client.py::TestOpenAI::test_parse_retry_after_header tests/test_client.py::TestAsyncOpenAI::test_parse_retry_after_header(32 passed)