Fix: Initialize auth_401_handler before token fetch
Bug Fix
Fixes AttributeError: 'ApiClientAdapter' object has no attribute 'auth_401_handler'
Reported Error:
ERROR: Failed to get new token, reason: ("'ApiClientAdapter' object has no attribute 'auth_401_handler'",)
Root Cause
During ApiClientAdapter.__init__, the code was calling __refresh_auth_token() before initializing auth_401_handler. When authentication settings are configured, __refresh_auth_token() calls call_api('/token'), which requires auth_401_handler to exist.
Why This Affected Some Deployments But Not Others
This bug only occurs when:
- Authentication settings are configured (key_id and key_secret are set)
- No existing AUTH_TOKEN is present (first initialization or token expired)
Many deployments didn't hit this because they either:
- Had valid tokens cached from previous sessions
- Used authentication methods that don't trigger token refresh during init
- Encountered the error but it didn't affect operation (token fetch failed silently in some cases)
When Bug Was Introduced
Introduced in commit 1f57c1e7 (October 13, 2025) when the 401 exponential backoff feature was added.
Changes
- Reordered initialization: Move
auth_401_handlersetup before__ensure_auth_token()call - Renamed method:
__refresh_auth_token→__ensure_auth_tokenfor clarity (it initializes, doesn't refresh) - Added documentation: Clear docstrings explaining initialization vs refresh behavior
Testing
- All 17 existing unit tests pass
- Verified fix with authentication settings that trigger token fetch during init
feel free to close
On Wed, Nov 12, 2025 at 12:22 PM Viren Baraiya @.***> wrote:
@.**** requested changes on this pull request.
this is on top of the changes we decided to not push to prod anymore.
— Reply to this email directly, view it on GitHub https://github.com/conductor-oss/python-sdk/pull/362#pullrequestreview-3455339210, or unsubscribe https://github.com/notifications/unsubscribe-auth/BXNK2TJ3YIRNPPJCX7W3PQ334OJHFAVCNFSM6AAAAACLWHC4COVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTINJVGMZTSMRRGA . You are receiving this because you authored the thread.Message ID: @.***>