Skip to content

fix(sdk): use explict api key before thread local#10657

Merged
dmitryduev merged 1 commit intomainfrom
pinglei/thread-local-api-key
Oct 8, 2025
Merged

fix(sdk): use explict api key before thread local#10657
dmitryduev merged 1 commit intomainfrom
pinglei/thread-local-api-key

Conversation

@pingleiwandb
Copy link
Copy Markdown
Contributor

@pingleiwandb pingleiwandb commented Oct 7, 2025

Description

No JIRA

User explicitly pass api key in wandb.Api(api_key=...) was picking up wrong key from thread local when switching between different keys.
The API key resolve logic should prefer the explicit key over the implicit thread local values.

  • I updated CHANGELOG.unreleased.md, or it's not applicable

Testing

How was this PR tested?

  • unit test

Manual test

# Update thread local manually to trigger the error
def download_with_manual_thread_local():
    cleanup()

    key1 = read_key("u1.key.txt")
    key2 = read_key("u2.key.txt")

    from wandb.sdk.internal.thread_local_settings import _thread_local_api_settings
    _thread_local_api_settings.cookie = {"wandb": "invalid-cookie-value"}
    _thread_local_api_settings.api_key = key1

    a2_name = f"{U2_ENTITY}/{P2}/10mb_test_switch_user_reg-team-2:latest"
    api2 = wandb.Api(api_key=key2) # key1 is used instead of key2
    artifact2 = api2.artifact(a2_name)
    artifact2.download(skip_cache=True)

@pingleiwandb pingleiwandb force-pushed the pinglei/thread-local-api-key branch 2 times, most recently from 6e2e365 to c5e4950 Compare October 7, 2025 22:59
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pingleiwandb pingleiwandb force-pushed the pinglei/thread-local-api-key branch from c5e4950 to 1501760 Compare October 7, 2025 23:13
Comment thread wandb/apis/public/api.py
@pingleiwandb pingleiwandb force-pushed the pinglei/thread-local-api-key branch from 1501760 to 19c53eb Compare October 7, 2025 23:34
@pingleiwandb pingleiwandb marked this pull request as ready for review October 7, 2025 23:37
@pingleiwandb pingleiwandb requested a review from a team as a code owner October 7, 2025 23:37
Comment thread CHANGELOG.unreleased.md Outdated
Comment thread tests/unit_tests/test_public_api/test_public_api.py Outdated
Comment thread tests/unit_tests/test_public_api/test_public_api.py Outdated
Comment thread wandb/apis/public/api.py
@timoffex timoffex requested review from a team and jacobromero October 8, 2025 00:21
This allow user to use different keys without picking up
wrong key from thread local.
@pingleiwandb pingleiwandb force-pushed the pinglei/thread-local-api-key branch from 19c53eb to 7e8da98 Compare October 8, 2025 00:34
@dmitryduev dmitryduev enabled auto-merge (squash) October 8, 2025 00:38
@dmitryduev dmitryduev merged commit b4dff5c into main Oct 8, 2025
34 checks passed
@dmitryduev dmitryduev deleted the pinglei/thread-local-api-key branch October 8, 2025 00:48
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.

4 participants