pola-rs/polars · error

{credential_provider}

Error message

{credential_provider}

What it means

Config.set_default_credential_provider accepts either a callable credential provider, a CredentialProviderFunction, or the literal string 'auto'. Any other plain string raises ValueError with the offending string as the message. None resets to default behavior.

Solutions

  1. Pass a callable, e.g. a function matching the CredentialProviderFunction signature.
  2. Pass the string 'auto' to let Polars pick the provider automatically.
  3. Pass None to reset to the default.
  4. Wrap the provider logic in your own function instead of naming it by string.

Example fix

// before
pl.Config.set_default_credential_provider("aws")
// after
def my_provider():
    return {"AWS_ACCESS_KEY_ID": "...", ...}
pl.Config.set_default_credential_provider(my_provider)
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(credential_provider, str) and credential_provider != "auto":
    raise ValueError("string provider must be 'auto'; pass a callable instead")
pl.Config.set_default_credential_provider(credential_provider)

Type guard

import collections.abc
def is_valid_provider(v) -> bool:
    return v is None or v == "auto" or callable(v)

Try / catch

try:
    pl.Config.set_default_credential_provider(provider)
except ValueError as e:
    raise TypeError(
        f"{e!r} is not a valid provider; pass a callable or 'auto'"
    ) from e

Prevention

When it happens

Trigger: pl.Config.set_default_credential_provider('aws'), 'boto3', or any string other than 'auto'.

Common situations: Passing a cloud provider name as a string assuming string configuration is supported (as in some other libraries); only 'auto' is a valid string.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/cfc22a6d9c2881f2. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/config.py:1732

        credential_provider
            Provide a function that can be called to provide cloud storage
            credentials. The function is expected to return a dictionary of
            credential keys along with an optional credential expiry time.

            Can also be set to None, which globally disables auto-initialization
            of credential providers, or "auto" (the default behavior).

        Examples
        --------
        >>> pl.Config.set_default_credential_provider(
        ...     pl.CredentialProviderAWS(
        ...         assume_role={"RoleArn": "...", "RoleSessionName": "..."}
        ...     )
        ... )
        <class 'polars.config.Config'>
        """
        if isinstance(credential_provider, str) and credential_provider != "auto":
            raise ValueError(credential_provider)

        _set_default_credential_provider(credential_provider)

        return cls

    @classmethod
    def reload_env_vars(cls) -> None:
        """
        Update the Polars config from the set environment variables.

        Normally you need not call this, it is only necessary when updating
        undocumented (environment-variable-only) config flags from Python after
        importing Polars.
        """
        plr.config_reload_env_vars()

View on GitHub (pinned to fe841f959e)