pola-rs/polars · error · ValueError

expiration time in STS response did not contain timezone…

Error message

expiration time in STS response did not contain timezone information

What it means

When finalizing an AWS STS AssumeRole response, polars requires the Expiration timestamp to be timezone-aware so it can compute an epoch expiry. A naive datetime means the STS endpoint returned a malformed/unexpected credential expiry, and polars raises ValueError rather than guessing a timezone.

Solutions

  1. Fix the STS endpoint/mock to return a timezone-qualified timestamp (e.g. '...Z' or explicit offset).
  2. Point the provider at the official AWS STS endpoint for the region.
  3. Update the mock/serializer to include tzinfo when constructing the datetime.

Example fix

// before
 {"Credentials": {"Expiration": datetime(2026, 1, 1, 12, 0, 0)}}
// after
 {"Credentials": {"Expiration": datetime(2026, 1, 1, 12, 0, 0, tzinfo=timezone.utc)}}
Defensive patterns

Strategy: try-catch

Validate before calling

exp = sts_response.get('Credentials', {}).get('Expiration')
if exp is not None and exp.tzinfo is None:
    raise ValueError('STS Expiration is timezone-naive; fix endpoint/mock')

Type guard

def has_tz(dt) -> bool:
    return getattr(dt, 'tzinfo', None) is not None

Try / catch

try:
    creds, expiry = provider.retrieve_credentials()
except ValueError as e:
    if 'did not contain timezone information' in str(e):
        # fall back to static credentials or fix the STS endpoint
        creds, expiry = static_credentials, None
    else:
        raise

Prevention

When it happens

Trigger: Using an assume-role credential provider where the STS response's Credentials.Expiration parses to a tz-naive datetime — typically from a custom/proxied/mocked STS endpoint or a non-AWS STS-compatible service.

Common situations: Testing against LocalStack or a mock STS that returns naive ISO timestamps; a corporate STS proxy that reformats Expiration; clock/region misconfiguration pointing at an unexpected endpoint.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/io/cloud/credential_provider/_providers.py:239

            if isinstance(expiry := getattr(creds, "_expiry_time", None), datetime)
            else None
        )

        return creds_dict, expiry

    def _finish_assume_role(self, session: Any) -> CredentialProviderFunctionReturn:
        assert self.assume_role is not None

        client = session.client("sts")

        sts_response = client.assume_role(**self.assume_role)
        creds = sts_response["Credentials"]

        expiry = creds["Expiration"]

        if expiry.tzinfo is None:
            msg = "expiration time in STS response did not contain timezone information"
            raise ValueError(msg)

        return {
            "aws_access_key_id": creds["AccessKeyId"],
            "aws_secret_access_key": creds["SecretAccessKey"],
            "aws_session_token": creds["SessionToken"],
        }, int(expiry.timestamp())

    # Called from Rust, mainly for AWS endpoint_url
    def _storage_update_options(self) -> dict[str, str]:
        if self._storage_options_has_endpoint_url:
            return {}

        try:
            config = self._session()._session.get_scoped_config()
        except ImportError:
            return {}

        if endpoint_url := config.get("endpoint_url"):

View on GitHub (pinned to fe841f959e)