Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): Fix credential provider error #21092

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions py-polars/polars/io/cloud/credential_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,20 +577,9 @@ def _maybe_init_credential_provider(
# Conservatively warn instead of hard error. It could just be
# set as a default environment flag.
issue_warning(msg, UserWarning)
# Note: Enclosing scope is also within a try-except.
# Note: Enclosing scope will catch ImportErrors
raise

# CredentialProviderAWS raises an error in some cases when
# `get_credentials()` returns None (e.g. the environment may not
# have / require credentials). We check this here and avoid
# auto-initializing it if that is the case.
try:
provider()
except Exception as e:
provider = None
msg = f"error retrieving credentials: {e}"
raise type(e)(msg) from e

elif storage_options is not None and any(
key.lower() not in OBJECT_STORE_CLIENT_OPTIONS for key in storage_options
):
Expand All @@ -600,9 +589,23 @@ def _maybe_init_credential_provider(

except ImportError as e:
if verbose:
msg = f"Unable to auto-select credential provider: {e}"
msg = f"unable to auto-select credential provider: {e!r}"
print(msg, file=sys.stderr)

if provider is not None:
# CredentialProviderAWS raises an error in some cases when
# `get_credentials()` returns None (e.g. the environment may not
# have / require credentials). We check this here and avoid
# using it if that is the case.
try:
provider()
except Exception as e:
provider = None

if verbose:
msg = f"unable to auto-select credential provider: {e!r}"
print(msg, file=sys.stderr)

if provider is not None and verbose:
msg = f"auto-selected credential provider: {type(provider).__name__}"
print(msg, file=sys.stderr)
Expand Down
Loading