azure-storage-file-datalake `rename` with `DataLakeLeaseClient`

未关闭
#50,200 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
azure, python
领域
backend

调研方向

Start with the reproducer using source.acquire_lease() and source.rename_file(...), then read the lease context-manager logic in azure/storage/filedatalake/_data_lake_lease.py and the rename implementations for rename_file, rename_directory, and _rename_file_system. Trace how source_lease is applied during rename and how release/__exit__ determines the target path; add a regression test covering rename inside the lease context and verify the lease is released against the renamed path.

由索引模型根据 Issue 内容生成。

描述

Client customer-reported needs-team-attention question Service Attention Storage
  • Package Name: azure-storage-file-datalake
  • Package Version: 12.26.1
  • Operating System: MacOS
  • Python Version: 3.13

Describe the bug
When calling acquire_lease in a Context Manager on azure.storage.filedatalake.FileSystemClient, azure.storage.filedatalake.DataLakeDirectoryClient, or azure.storage.filedatalake.DataLakeFileClient followed by a _rename_file_system, rename_directory, or rename_file, respectively, causes an error to be thrown when exiting the Context Manager.

Additionally, this leaves the newly renamed file in a leased state as it maintains the lease the previously named file had on it when it was renamed.

To Reproduce
Steps to reproduce the behavior:

credential = azure.identity.DefaultAzureCredential()
connection = azure.storage.filedatalake.DataLakeServiceClient(
    account_url=f"https://{storage_account}.dfs.core.windows.net",
    credential=credential,
)
source = connection.get_file_client(
    file_system="abc",
    file_path="def.txt",
)
with  source.acquire_lease() as lease:
    source.rename_file("ghi/jkl.txt", lease=lease)

Throws:

    with source.acquire_lease() as lease:
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/filedatalake/_data_lake_lease.py", line 70, in __exit__
    self.release()
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/tracing/decorator.py", line 119, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/filedatalake/_data_lake_lease.py", line 183, in release
    self._blob_lease_client.release(**kwargs)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/tracing/decorator.py", line 119, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/_lease.py", line 228, in release
    process_storage_error(error)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/_shared/response_handlers.py", line 198, in process_storage_error
    raise error from None
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/_lease.py", line 220, in release
    response: Any = self._client.release_lease(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/tracing/decorator.py", line 119, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/_generated/operations/_blob_operations.py", line 3155, in release_lease
    map_error(status_code=response.status_code, response=response, error_map=error_map)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/exceptions.py", line 163, in map_error
    raise error
azure.core.exceptions.ResourceNotFoundError: The specified blob does not exist.
RequestId:d8882ade-701e-009b-30c7-81fbb5000000
Time:2026-12-01T19:07:51.6008552Z
ErrorCode:BlobNotFound
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:d8882ade-7013-019b-30d7-abcbb5000000
Time:2026-12-01T19:00:00.0000000Z</Message></Error>

Expected behavior
I would expect the above code to complete without an Error being thrown. The result of the rename_file call should appropriately mutate the state of the azure.storage.filedatalake.DataLakeLeaseClient, so it correctly points to the renamed location and calling release or __exit__ should appropriately release the lease on the renamed location.

Additional context
If the above described mutation of the passed in azure.storage.filedatalake.DataLakeLeaseClient is deemed a change that is unacceptable, then I would expect more information be supplied in the pydoc description of the source_lease kwarg so it is clear that passing a azure.storage.filedatalake.DataLakeLeaseClient will render that object useless and it should not be used in a Context Manager.

主要语言
Python
星标
5.6k
派生
3.4k
平均合并
1 天 23 小时
30 天内合并 PR
189

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/azure-sdk-for-python 的其他 Issue

查看 Azure/azure-sdk-for-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。