Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Unreleased
----------
- Added `**kwargs` to `AzureBlobFileSystem.exists()`
- Populate `AzureBlobFile.version_id` on write when `version_aware` is enabled.

2026.2.0
--------
Expand Down
19 changes: 13 additions & 6 deletions adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,10 @@ def __init__(
by `cache_type`.

version_id : str
Optional version to read the file at. If not specified this will
default to the current version of the object. This is only used for
reading.
Optional version of the blob. For reads, specifies which version to
read; if not given, defaults to the current version. On write, this
attribute is populated with the version created by the upload when the
filesystem has ``version_aware=True``.

kwargs: dict
Passed to AbstractBufferedFile
Expand Down Expand Up @@ -2264,9 +2265,11 @@ async def _async_upload_chunk(self, final: bool = False, **kwargs):
async with self.container_client.get_blob_client(
blob=self.blob
) as bc:
await bc.commit_block_list(
response = await bc.commit_block_list(
block_list=block_list, metadata=self.metadata, **commit_kw
)
if self.fs.version_aware:
self.version_id = response.get("version_id")
except ResourceExistsError as e:
raise FileExistsError(self.path) from e
except Exception as e:
Expand All @@ -2278,23 +2281,27 @@ async def _async_upload_chunk(self, final: bool = False, **kwargs):
async with self.container_client.get_blob_client(
blob=self.blob
) as bc:
await bc.upload_blob(
response = await bc.upload_blob(
data=data,
metadata=self.metadata,
overwrite=(self.mode == "wb"),
)
if self.fs.version_aware:
self.version_id = response.get("version_id")
elif length == 0 and final:
# just finalize
block_list = [BlobBlock(_id) for _id in self._block_list]
async with self.container_client.get_blob_client(
blob=self.blob
) as bc:
try:
await bc.commit_block_list(
response = await bc.commit_block_list(
block_list=block_list,
metadata=self.metadata,
**commit_kw,
)
if self.fs.version_aware:
self.version_id = response.get("version_id")
except ResourceExistsError:
raise FileExistsError(self.path)
else:
Expand Down
46 changes: 46 additions & 0 deletions adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,52 @@ def test_uses_block_size_for_partitioned_uploads(storage, mocker):
assert len(mock_commit_block_list.call_args.kwargs["block_list"]) == expected_blocks


def test_write_populates_version_id_when_version_aware(storage, mocker):
from azure.storage.blob.aio import BlobClient

fs = AzureBlobFileSystem(
account_name=storage.account_name,
connection_string=CONN_STR,
version_aware=True,
skip_instance_cache=True,
)

mock_commit_block_list = mocker.patch.object(
BlobClient,
"commit_block_list",
return_value={"version_id": "test-version-id"},
)

with fs.open("data/version-aware-write.bin", "wb") as f:
f.write(b"hello world")

assert mock_commit_block_list.called
assert f.version_id == "test-version-id"


def test_write_does_not_populate_version_id_when_not_version_aware(storage, mocker):
from azure.storage.blob.aio import BlobClient

fs = AzureBlobFileSystem(
account_name=storage.account_name,
connection_string=CONN_STR,
version_aware=False,
skip_instance_cache=True,
)

mock_commit_block_list = mocker.patch.object(
BlobClient,
"commit_block_list",
return_value={"version_id": "test-version-id"},
)

with fs.open("data/not-version-aware-wb.bin", "wb") as f:
f.write(b"hello world")

assert mock_commit_block_list.called
assert f.version_id is None


@pytest.mark.parametrize(
"filesystem_blocksize, file_blocksize, expected_blocksize, expected_filesystem_blocksize",
[
Expand Down