Skip to content

Commit

Permalink
Merge branch 'main' into session_refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant committed Feb 18, 2025
2 parents e134659 + 744d9c6 commit d6aea66
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Run Tests
shell: bash -l {0}
run: pytest -vv -s s3fs -k test_write_blocks
run: pytest -vv -s s3fs


pre-commit:
Expand Down
14 changes: 13 additions & 1 deletion s3fs/tests/derived/s3fs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ class TestS3fsPut(abstract.AbstractPutTests, S3fsFixtures):
pass


def botocore_too_old():
import botocore
from packaging.version import parse

MIN_BOTOCORE_VERSION = "1.33.2"

return parse(botocore.__version__) < parse(MIN_BOTOCORE_VERSION)


class TestS3fsPipe(abstract.AbstractPipeTests, S3fsFixtures):
pass

test_pipe_exclusive = pytest.mark.skipif(
botocore_too_old(), reason="Older botocore doesn't support exclusive writes"
)(abstract.AbstractPipeTests.test_pipe_exclusive)


class TestS3fsOpen(abstract.AbstractOpenTests, S3fsFixtures):
Expand Down
2 changes: 1 addition & 1 deletion s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_info(s3):
info.pop("ContentType")
linfo.pop("Key")
linfo.pop("Size")
linfo.pop("ChecksumAlgorithm")
linfo.pop("ChecksumAlgorithm", None) # field DNE in some S3-compatible providers
assert info == linfo
parent = a.rsplit("/", 1)[0]
s3.invalidate_cache() # remove full path from the cache
Expand Down
26 changes: 14 additions & 12 deletions s3fs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ async def get_bucket_client(self, bucket_name=None):
try:
response = await general_client.head_bucket(Bucket=bucket_name)
except ClientError as e:
region = (
e.response["ResponseMetadata"]
.get("HTTPHeaders", {})
.get("x-amz-bucket-region")
logger.debug("RC: HEAD_BUCKET call for %r has failed", bucket_name)
response = e.response

region = (
response["ResponseMetadata"]
.get("HTTPHeaders", {})
.get("x-amz-bucket-region")
)

if not region:
logger.debug(
"RC: No region in HEAD_BUCKET call response for %r, returning the general client",
bucket_name,
)
if not region:
logger.debug(
"RC: HEAD_BUCKET call for %r has failed, returning the general client",
bucket_name,
)
return general_client
else:
region = response["ResponseMetadata"]["HTTPHeaders"]["x-amz-bucket-region"]
return general_client

if region not in self._regions:
logger.debug(
Expand Down

0 comments on commit d6aea66

Please sign in to comment.