pola-rs/polars · error · ValueError
the provided `credential` object
Error message
the provided `credential` object {credential!r} does not have a `get_token()` method. What it means
CredentialProviderAzure's constructor accepts a `credential` object that must expose get_token() (an azure-identity TokenCredential). Passing an object without that method raises ValueError, and if no Azure storage account key can be retrieved instead, the azure-identity module availability is then enforced.
Solutions
- Pass an azure-identity TokenCredential, e.g. azure.identity.ClientSecretCredential(tenant_id, client_id, client_secret).
- If you have a connection string/account key, use the account-key path instead of the credential argument.
- Add a get_token() method conforming to the TokenCredential protocol if using a custom credential.
Example fix
// before
provider = pl.CredentialProviderAzure(credential={"tenantId": t, "clientId": c, "clientSecret": s})
// after
from azure.identity import ClientSecretCredential
provider = pl.CredentialProviderAzure(credential=ClientSecretCredential(t, c, s)) Defensive patterns
Strategy: type-guard
Validate before calling
cred = ... # user-supplied
if cred is not None and not callable(getattr(cred, 'get_token', None)):
raise TypeError('credential must implement get_token() (azure-identity TokenCredential)') Type guard
from typing import Any, Protocol
class TokenCredential(Protocol):
def get_token(self, *scopes: str, **kwargs: Any) -> Any: ...
def is_token_credential(obj: Any) -> bool:
return callable(getattr(obj, 'get_token', None)) Try / catch
try:
provider = pl.CredentialProviderAzure(credential=cred)
except ValueError as e:
if 'get_token()' in str(e):
from azure.identity import DefaultAzureCredential
provider = pl.CredentialProviderAzure(credential=DefaultAzureCredential())
else:
raise Prevention
- Only pass azure-identity TokenCredential instances (ClientSecretCredential, DefaultAzureCredential, etc.).
- Never pass strings, dicts, or connection strings as `credential` — use the account-key path for those.
- Type-annotate the credential parameter as TokenCredential in your wrappers.
When it happens
Trigger: Passing credential=<obj> where obj lacks get_token — e.g. a raw client secret string, a service-principal dict, a boto3-style credentials object, or a custom class without get_token.
Common situations: Confusing Azure account keys/Connection strings with TokenCredential objects; passing ClientSecretCredential wrapped or misconstructed; wiring AWS credentials into an Azure provider by mistake.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- azure-identity must be installed to use…
- `arctan2` expected a `str` or `Expr` got a
- `arctan2` expected a `str` or `Expr` got a
- cannot convert Python type
- cannot use credential_provider when passing a DeltaTable…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/77fef9159caccc1d.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/cloud/credential_provider/_providers.py:379
msg = "`CredentialProviderAzure` functionality is considered unstable"
issue_unstable_warning(msg)
self.account_name = _storage_account
self.scopes = (
scopes if scopes is not None else ["https://storage.azure.com/.default"]
)
self.tenant_id = tenant_id
self.credential = credential
if credential is not None:
# If the user passes a credential class, we just need to ensure it
# has a `get_token()` method.
if not hasattr(credential, "get_token"):
msg = (
f"the provided `credential` object {credential!r} does "
"not have a `get_token()` method."
)
raise ValueError(msg)
# We don't need the module if we are permitted and able to retrieve the
# account key from the Azure CLI.
elif self._try_get_azure_storage_account_credential_if_permitted() is None:
self._ensure_module_availability()
if verbose():
eprint(
"[CredentialProviderAzure]: "
f"{self.account_name = } "
f"{self.tenant_id = } "
f"{self.scopes = } "
)
super().__init__()
def retrieve_credentials_impl(self) -> CredentialProviderFunctionReturn:
"""Fetch the credentials."""View on GitHub (pinned to fe841f959e)