Skip to content

PR #453 breaks the use of DefaultAzureCredential for a Azure Storage Account Gen2 #476

@johschmidt42

Description

@johschmidt42

With #453, in the AzureBlobClient class, an instance of the DataLakeServiceClient class is created if a blob_service_client is passed as a parameter. The Storage Account might not have a hierarchical namespace (datalake). I would expect that the AzureBlobClient does not try to create an instance of the DataLakeServiceClient class.

The error:

  File "/Users/XXX/Library/Caches/pypoetry/virtualenvs/some-project/lib/python3.11/site-packages/cloudpathlib/azure/azblobclient.py", line 117, in __init__
    blob_service_client.credential.account_name,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DefaultAzureCredential' object has no attribute 'account_name'

The code:

from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
from cloudpathlib import AzureBlobClient

# Define your Azure Blob Storage details
account_url = "https://storage-account.blob.core.windows.net"
container_name = "az://container-name"
blob_name = "some/blob.txt"

# Initialize the DefaultAzureCredential
credential = DefaultAzureCredential()

blob_service_client = BlobServiceClient(account_url=account_url, credential=credential)

# Create an AzureBlobClient
client = AzureBlobClient(blob_service_client=blob_service_client)

# Construct the full path to the blob
blob_path = f"{container_name}/{blob_name}"

# Use the client to read the blob
blob = client.CloudPath(blob_path)

if __name__ == "__main__":
    # Read the content of the blob
    with blob.open("r") as file:
        content = file.read()

Therefore, 0.19.0 becomes unusable to interact with blob data on a Azure Storage Account Gen2 without hierarchical namespace. 0.18.1 works just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions