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

add missing await on delete_blob call per issue 459 #460

Merged
merged 4 commits into from
Mar 21, 2024
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
2 changes: 1 addition & 1 deletion adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ async def _rm_files(
# marker before the directory is empty. If these are deleted out of order we will get
# `This operation is not permitted on a non-empty directory.` on hierarchical namespace storage accounts.
for directory_marker in reversed(directory_markers):
cc.delete_blob(directory_marker)
await cc.delete_blob(directory_marker)

for file in file_paths:
self.invalidate_cache(self._parent(file))
Expand Down
42 changes: 32 additions & 10 deletions adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import tempfile
from unittest import mock

import azure.storage.blob
import azure.storage.blob.aio
import dask.dataframe as dd
import numpy as np
Expand Down Expand Up @@ -754,14 +753,8 @@ def test_rm_recursive(mock_delete_blob, storage):
mock.ANY, "root/c"
), "The directory deletion should be the last call"


@mock.patch.object(
azure.storage.blob.aio.ContainerClient,
"delete_blob",
side_effect=azure.storage.blob.aio.ContainerClient.delete_blob,
autospec=True,
)
def test_rm_recursive2(mock_delete_blob, storage):
@pytest.mark.filterwarnings("error")
def test_rm_recursive2(storage):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified this test to remove the mocking so the delete_blob calls are executed asynchronously. This test ensures that the files in data/rootare in fact removed. Also, the decorator will raise the RuntimeWarning emitted from the missing await (regression).

fs = AzureBlobFileSystem(
account_name=storage.account_name, connection_string=CONN_STR
)
Expand All @@ -774,7 +767,36 @@ def test_rm_recursive2(mock_delete_blob, storage):
with pytest.raises(FileNotFoundError):
fs.ls("data/root")

last_deleted_paths = [call.args[1] for call in mock_delete_blob.mock_calls[-7:]]

async def test_rm_recursive_call_order(storage, mocker):
Copy link
Contributor Author

@johnmacnamararseg johnmacnamararseg Feb 13, 2024

Choose a reason for hiding this comment

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

Since fs.rm validates that the files are actually removed, there wasn't an easy way to mock delete_blob so that still ran the deletes asynchronously as a side effect (someone might have a clever way to do this). So instead I just explicitly supply the file paths under data/root , call fs._rm_files, and assert the call order similar to how the previous test was working

from azure.storage.blob.aio import ContainerClient

delete_blob_mock = mocker.patch.object(ContainerClient, "delete_blob", return_value=None)
fs = AzureBlobFileSystem(
account_name=storage.account_name, connection_string=CONN_STR
)

container_name = "data"
file_paths = [
"root/a",
"root/a/file.txt",
"root/a1",
"root/a1/file1.txt",
"root/b",
"root/b/file.txt",
"root",
"root/c",
"root/c/file1.txt",
"root/c/file2.txt",
"root/d",
"root/d/file_with_metadata.txt",
"root/e+f",
"root/e+f/file1.txt",
"root/e+f/file2.txt",
"root/rfile.txt"
]
await fs._rm_files(container_name=container_name, file_paths=file_paths)
last_deleted_paths = [call.args[0] for call in delete_blob_mock.call_args_list[-7:]]
assert last_deleted_paths == [
"root/e+f",
"root/d",
Expand Down