Skip to content

fix(core): honor explicit tenant access token when cache is enabled#197

Open
amdoi7 wants to merge 1 commit intolarksuite:v3_mainfrom
amdoi7:fix/tenant-token-override-cache
Open

fix(core): honor explicit tenant access token when cache is enabled#197
amdoi7 wants to merge 1 commit intolarksuite:v3_mainfrom
amdoi7:fix/tenant-token-override-cache

Conversation

@amdoi7
Copy link
Copy Markdown

@amdoi7 amdoi7 commented Mar 28, 2026

Fixes #198

Summary

  • keep WithTenantAccessToken(...) as the highest-priority tenant token source
  • only fall back to tokenManager.getTenantAccessToken(...) when no explicit tenant token is provided
  • add regression tests for both the explicit-token and cache-fallback paths

Root cause

In core/reqtranslator.go, the AccessTokenTypeTenant branch always called tokenManager.getTenantAccessToken(...) when EnableTokenCache=true, even if RequestOption.TenantAccessToken had already been set.

That meant an explicit tenant token could be silently overwritten by the cache/token-manager path.

Fix

Change the tenant token resolution logic from:

if config.EnableTokenCache {

to:

if config.EnableTokenCache && tenantAccessToken == "" {

This matches the existing AccessTokenTypeApp behavior and preserves the expected precedence:

  • explicit tenant token
  • cached/generated tenant token

Tests

Added:

  • TestTranslate_ExplicitTenantAccessTokenBypassesCache
  • TestTranslate_TenantAccessTokenUsesCacheWhenExplicitTokenMissing

Validated with:

go test ./core -run 'TestTranslate_(ExplicitTenantAccessTokenBypassesCache|TenantAccessTokenUsesCacheWhenExplicitTokenMissing)$'

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.

bug(core): WithTenantAccessToken is ignored when EnableTokenCache is true

1 participant