{"record":{"id":"247486d780bb5214","repo":"pola-rs/polars","slug":"expiration-time-in-sts-response-did-not-contain-ti","errorCode":null,"errorMessage":"expiration time in STS response did not contain timezone information","messagePattern":"expiration time in STS response did not contain timezone information","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/cloud/credential_provider/_providers.py","lineNumber":239,"sourceCode":"            if isinstance(expiry := getattr(creds, \"_expiry_time\", None), datetime)\n            else None\n        )\n\n        return creds_dict, expiry\n\n    def _finish_assume_role(self, session: Any) -> CredentialProviderFunctionReturn:\n        assert self.assume_role is not None\n\n        client = session.client(\"sts\")\n\n        sts_response = client.assume_role(**self.assume_role)\n        creds = sts_response[\"Credentials\"]\n\n        expiry = creds[\"Expiration\"]\n\n        if expiry.tzinfo is None:\n            msg = \"expiration time in STS response did not contain timezone information\"\n            raise ValueError(msg)\n\n        return {\n            \"aws_access_key_id\": creds[\"AccessKeyId\"],\n            \"aws_secret_access_key\": creds[\"SecretAccessKey\"],\n            \"aws_session_token\": creds[\"SessionToken\"],\n        }, int(expiry.timestamp())\n\n    # Called from Rust, mainly for AWS endpoint_url\n    def _storage_update_options(self) -> dict[str, str]:\n        if self._storage_options_has_endpoint_url:\n            return {}\n\n        try:\n            config = self._session()._session.get_scoped_config()\n        except ImportError:\n            return {}\n\n        if endpoint_url := config.get(\"endpoint_url\"):","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/cloud/credential_provider/_providers.py#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the STS endpoint/mock to return a timezone-qualified timestamp (e.g. '...Z' or explicit offset).","Point the provider at the official AWS STS endpoint for the region.","Update the mock/serializer to include tzinfo when constructing the datetime."],"exampleFix":"// before\n {\"Credentials\": {\"Expiration\": datetime(2026, 1, 1, 12, 0, 0)}}\n// after\n {\"Credentials\": {\"Expiration\": datetime(2026, 1, 1, 12, 0, 0, tzinfo=timezone.utc)}}","handlingStrategy":"try-catch","validationCode":"exp = sts_response.get('Credentials', {}).get('Expiration')\nif exp is not None and exp.tzinfo is None:\n    raise ValueError('STS Expiration is timezone-naive; fix endpoint/mock')","typeGuard":"def has_tz(dt) -> bool:\n    return getattr(dt, 'tzinfo', None) is not None","tryCatchPattern":"try:\n    creds, expiry = provider.retrieve_credentials()\nexcept ValueError as e:\n    if 'did not contain timezone information' in str(e):\n        # fall back to static credentials or fix the STS endpoint\n        creds, expiry = static_credentials, None\n    else:\n        raise","preventionTips":["In tests, have STS mocks return ISO-8601 timestamps with 'Z' or explicit offsets.","Point assume-role configuration at official AWS STS endpoints.","Validate third-party STS-compatible services return tz-aware Expiration values."],"tags":["python","aws","sts","timezone"],"backgroundTag":"unexpected-response-shape","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}