conductor-python icon indicating copy to clipboard operation
conductor-python copied to clipboard

Fix: Initialize auth_401_handler before token fetch

Open nthmost-orkes opened this issue 1 month ago • 1 comments

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:

  1. Authentication settings are configured (key_id and key_secret are set)
  2. 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

  1. Reordered initialization: Move auth_401_handler setup before __ensure_auth_token() call
  2. Renamed method: __refresh_auth_token__ensure_auth_token for clarity (it initializes, doesn't refresh)
  3. 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

nthmost-orkes avatar Nov 10 '25 19:11 nthmost-orkes

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: @.***>

nthmost-orkes avatar Nov 13 '25 05:11 nthmost-orkes