pola-rs/polars · error · ValueError

unsupported: cannot combine aws_profile with

Error message

unsupported: cannot combine aws_profile with {unhandled_key} in storage_options

What it means

The credential provider builder rejects combining the aws_profile selection mechanism with any other unhandled storage_options key, since profile-based credential resolution cannot be reconciled with explicit credentials in the same options dict.

Solutions

  1. Remove aws_profile from storage_options when supplying explicit credentials.
  2. Or remove the explicit credential keys and rely solely on the AWS profile.
  3. Move profile selection to the aws CLI/config files (~/.aws/config) instead of storage_options.

Example fix

// before
 opts = {"aws_profile": "prod", "aws_access_key_id": k, "aws_secret_access_key": s}
// after
 opts = {"aws_access_key_id": k, "aws_secret_access_key": s}  # drop aws_profile
Defensive patterns

Strategy: validation

Validate before calling

if 'aws_profile' in opts and len(opts) > 1:
    raise ValueError('aws_profile cannot be combined with other credential keys in storage_options')

Type guard

def opts_are_consistent(opts: dict) -> bool:
    return not ('aws_profile' in opts and any(k != 'aws_profile' for k in opts))

Try / catch

try:
    lf = pl.scan_parquet(url, storage_options=opts)
except ValueError as e:
    if 'cannot combine aws_profile' in str(e):
        opts = {k: v for k, v in opts.items() if k == 'aws_profile'}
        lf = pl.scan_parquet(url, storage_options=opts)
    else:
        raise

Prevention

When it happens

Trigger: Passing storage_options that include both aws_profile (e.g. {'aws_profile': 'prod'}) and another credential key such as aws_access_key_id/aws_session_token, or a cloud provider token, when building an AWS credential provider.

Common situations: Merging two configs — a shared base dict containing aws_profile plus a per-environment dict with explicit keys; leftover keys after switching auth strategies; templated storage_options that concatenate both styles.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/io/cloud/credential_provider/_builder.py:484

                        "aws_endpoint",
                        "aws_endpoint_url",
                        "endpoint",
                        "endpoint_url",
                    }:
                        has_endpoint_url = True
                    elif k in AUTOINIT_IGNORED_KEYS:
                        continue
                    else:
                        # We assume this is some sort of access key
                        unhandled_key = k

            if unhandled_key is not None:
                if profile is not None:
                    msg = (
                        "unsupported: cannot combine aws_profile with "
                        f"{unhandled_key} in storage_options"
                    )
                    raise ValueError(msg)

            if (
                unhandled_key is None
                and (default := get_default_credential_provider()) is not None
            ):
                return default

            return CredentialProviderBuilder(
                AutoInit(
                    CredentialProviderAWS,
                    profile_name=profile,
                    region_name=region or default_region,
                    _auto_init_unhandled_key=unhandled_key,
                    _storage_options_has_endpoint_url=has_endpoint_url,
                )
            )

        elif _is_gcp_cloud(scheme):

View on GitHub (pinned to fe841f959e)