Skip to content

Commit

Permalink
fix: Do not attempt to load default credentials when `credential_prov…
Browse files Browse the repository at this point in the history
…ider` is given (#19589)
  • Loading branch information
nameexhaustion authored Nov 1, 2024
1 parent 5053252 commit d75d8d9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
21 changes: 18 additions & 3 deletions crates/polars-io/src/cloud/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ impl CloudOptions {
pub async fn build_aws(&self, url: &str) -> PolarsResult<impl object_store::ObjectStore> {
use super::credential_provider::IntoCredentialProvider;

let mut builder = AmazonS3Builder::from_env().with_url(url);
let mut builder = {
if self.credential_provider.is_none() {
AmazonS3Builder::from_env()
} else {
AmazonS3Builder::new()
}
}
.with_url(url);
if let Some(options) = &self.config {
let CloudConfig::Aws(options) = options else {
panic!("impl error: cloud type mismatch")
Expand Down Expand Up @@ -393,7 +400,11 @@ impl CloudOptions {
pub fn build_azure(&self, url: &str) -> PolarsResult<impl object_store::ObjectStore> {
use super::credential_provider::IntoCredentialProvider;

let mut builder = MicrosoftAzureBuilder::from_env();
let mut builder = if self.credential_provider.is_none() {
MicrosoftAzureBuilder::from_env()
} else {
MicrosoftAzureBuilder::new()
};
if let Some(options) = &self.config {
let CloudConfig::Azure(options) = options else {
panic!("impl error: cloud type mismatch")
Expand Down Expand Up @@ -434,7 +445,11 @@ impl CloudOptions {
pub fn build_gcp(&self, url: &str) -> PolarsResult<impl object_store::ObjectStore> {
use super::credential_provider::IntoCredentialProvider;

let mut builder = GoogleCloudStorageBuilder::from_env();
let mut builder = if self.credential_provider.is_none() {
GoogleCloudStorageBuilder::from_env()
} else {
GoogleCloudStorageBuilder::new()
};
if let Some(options) = &self.config {
let CloudConfig::Gcp(options) = options else {
panic!("impl error: cloud type mismatch")
Expand Down
22 changes: 22 additions & 0 deletions py-polars/tests/unit/io/cloud/test_credential_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

import polars as pl
from polars.exceptions import ComputeError


def test_credential_provider_skips_config_autoload(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv("GOOGLE_SERVICE_ACCOUNT_PATH", "__non_existent")

with pytest.raises(ComputeError, match="__non_existent"):
pl.scan_parquet("gs://.../...", credential_provider=None).collect()

err_magic = "err_magic_3"

def raises() -> pl.CredentialProviderFunctionReturn:
raise AssertionError(err_magic)

# We should get a different error raised by our `raises()` function.
with pytest.raises(ComputeError, match=err_magic):
pl.scan_parquet("gs://.../...", credential_provider=raises).collect()

0 comments on commit d75d8d9

Please sign in to comment.