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

487 live tests #491

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed `CloudPath(...) / other` to correctly attempt to fall back on `other`'s `__rtruediv__` implementation, in order to support classes that explicitly support the `/` with a `CloudPath` instance. Previously, this would always raise a `TypeError` if `other` were not a `str` or `PurePosixPath`. (PR [#479](https://github.com/drivendataorg/cloudpathlib/pull/479))
- Fixed an uncaught exception on Azure Gen2 storage accounts with HNS enabled when used with `DefaultAzureCredential`. (Issue [#486](https://github.com/drivendataorg/cloudpathlib/issues/486))

## v0.20.0 (2024-10-18)

Expand Down
36 changes: 25 additions & 11 deletions cloudpathlib/azure/azblobclient.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from datetime import datetime, timedelta
import mimetypes
import os
from http import HTTPStatus
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, Optional, Tuple, Union

try:
from typing import cast
except ImportError:
from typing_extensions import cast

Check warning on line 11 in cloudpathlib/azure/azblobclient.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/azure/azblobclient.py#L10-L11

Added lines #L10 - L11 were not covered by tests
Comment on lines +8 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't from typing_extensions import cast suffice, as it already does a very similar thing under the hood?


from ..client import Client, register_client_class
from ..cloudpath import implementation_registry
Expand All @@ -13,7 +18,7 @@


try:
from azure.core.exceptions import ResourceNotFoundError
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
from azure.core.credentials import AzureNamedKeyCredential

from azure.storage.blob import (
Expand Down Expand Up @@ -202,20 +207,29 @@
try:
account_info = self.service_client.get_account_information() # type: ignore
self._hns_enabled = account_info.get("is_hns_enabled", False) # type: ignore

# get_account_information() not supported with this credential; we have to fallback to
# checking if the root directory exists and is a has 'metadata': {'hdi_isfolder': 'true'}
except ResourceNotFoundError:
# get_account_information() not supported with this credential; we have to fallback to
# checking if the root directory exists and is a has 'metadata': {'hdi_isfolder': 'true'}
root_dir = self.service_client.get_blob_client(
container=cloud_path.container, blob="/"
)
self._hns_enabled = (
root_dir.exists()
and root_dir.get_blob_properties().metadata.get("hdi_isfolder", False)
== "true"
)
return self._check_hns_root_metadata(cloud_path)
except HttpResponseError as error:
if error.status_code == HTTPStatus.FORBIDDEN:
self._check_hns_root_metadata(cloud_path)

Check warning on line 217 in cloudpathlib/azure/azblobclient.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/azure/azblobclient.py#L215-L217

Added lines #L215 - L217 were not covered by tests
Comment on lines +214 to +217
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: to be consistent, either both of these should be a return statement or none of them should.

else:
raise

Check warning on line 219 in cloudpathlib/azure/azblobclient.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/azure/azblobclient.py#L219

Added line #L219 was not covered by tests

return self._hns_enabled

def _check_hns_root_metadata(self, cloud_path: AzureBlobPath) -> bool:
root_dir = self.service_client.get_blob_client(container=cloud_path.container, blob="/")

self._hns_enabled = (
root_dir.exists()
and root_dir.get_blob_properties().metadata.get("hdi_isfolder", False) == "true"
)

return cast(bool, self._hns_enabled)

def _get_metadata(
self, cloud_path: AzureBlobPath
) -> Union["BlobProperties", "FileProperties", Dict[str, Any]]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"typing_extensions>4 ; python_version < '3.11'",
"typing-extensions>4 ; python_version < '3.11'",
]

[project.optional-dependencies]
Expand Down
Loading