fix: always send tenant headers in OpenViking _headers() when account/user are set

OpenViking 0.3.x requires X-OpenViking-Account and X-OpenViking-User headers for ROOT API key requests to tenant-scoped APIs. Previously the `!="default"` guard skipped these headers when account/user were the literal string "default", causing INVALID_ARGUMENT errors.

Remove the `!="default"` guard so headers are sent whenever account/user are truthy. Empty strings are still correctly skipped since `""` is falsy.

Update tests to reflect the new behavior:
- test_viking_client_headers_send_tenant_when_default: asserts "default" headers ARE present
- test_viking_client_headers_send_tenant_when_empty_falls_back_to_default: asserts "default" headers ARE present from constructor fallback

Based on #21775 by @happy5318
This commit is contained in:
kshitij 2026-05-09 01:53:19 -07:00 committed by GitHub
parent c7e8add120
commit 8fb3e2d63a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 16 deletions

View file

@ -100,18 +100,19 @@ class _VikingClient:
raise ImportError("httpx is required for OpenViking: pip install httpx")
def _headers(self) -> dict:
# Only send tenant headers when the user actually configured them.
# Legacy installs had account/user defaulted to the literal string
# "default" — treat that as unset so authenticated remote servers
# that derive tenancy from the Bearer key aren't overridden by a
# bogus tenant value.
# Always send tenant headers when account/user are configured.
# OpenViking 0.3.x requires X-OpenViking-Account and X-OpenViking-User
# for ROOT API key requests to tenant-scoped APIs — omitting them
# causes INVALID_ARGUMENT errors even when account="default".
# User-level keys can omit them (server derives tenancy from the key),
# but ROOT keys must always include them explicitly.
h = {
"Content-Type": "application/json",
"X-OpenViking-Agent": self._agent,
}
if self._account and self._account != "default":
if self._account:
h["X-OpenViking-Account"] = self._account
if self._user and self._user != "default":
if self._user:
h["X-OpenViking-User"] = self._user
if self._api_key:
h["X-API-Key"] = self._api_key