Skip to content

Commit fb60783

Browse files
Add changelog, add prefix ValueError for list_blobs, list_blobs_names, and walk_blobs (#34443)
1 parent 8c651d9 commit fb60783

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

sdk/storage/azure-storage-blob/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ using async OAuth credentials.
1616
- Fixed an typing issue which incorrectly typed the `readinto` API. The correct input type is `IO[bytes]`.
1717
- Fixed a typo in the initialization of `completion_time` for the `CopyProperties` model.
1818

19+
### Other Changes
20+
- Passing `prefix` to the following `ContainerClient` APIs now raises a `ValueError`:
21+
`list_blobs`, `list_blobs_names`, and `walk_blobs`. This change was made to avoid confusion for filtering results.
22+
The `name_starts_with` parameter is the correct prameter to pass for filtering.
23+
1924
## 12.19.0 (2023-11-07)
2025

2126
### Features Added

sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,11 @@ def set_container_access_policy(
792792
process_storage_error(error)
793793

794794
@distributed_trace
795-
def list_blobs(self, name_starts_with=None, include=None, **kwargs):
796-
# type: (Optional[str], Optional[Union[str, List[str]]], **Any) -> ItemPaged[BlobProperties]
795+
def list_blobs(
796+
self, name_starts_with: Optional[str] = None,
797+
include: Optional[Union[str, List[str]]] = None,
798+
**kwargs: Any
799+
) -> ItemPaged[BlobProperties]:
797800
"""Returns a generator to list the blobs under the specified container.
798801
The generator will lazily follow the continuation tokens returned by
799802
the service.
@@ -824,6 +827,10 @@ def list_blobs(self, name_starts_with=None, include=None, **kwargs):
824827
:dedent: 8
825828
:caption: List the blobs in the container.
826829
"""
830+
if kwargs.pop('prefix', None):
831+
raise ValueError("Passing 'prefix' has no effect on filtering, " +
832+
"please use the 'name_starts_with' parameter instead.")
833+
827834
if include and not isinstance(include, list):
828835
include = [include]
829836

@@ -860,6 +867,10 @@ def list_blob_names(self, **kwargs: Any) -> ItemPaged[str]:
860867
:returns: An iterable (auto-paging) response of blob names as strings.
861868
:rtype: ~azure.core.paging.ItemPaged[str]
862869
"""
870+
if kwargs.pop('prefix', None):
871+
raise ValueError("Passing 'prefix' has no effect on filtering, " +
872+
"please use the 'name_starts_with' parameter instead.")
873+
863874
name_starts_with = kwargs.pop('name_starts_with', None)
864875
results_per_page = kwargs.pop('results_per_page', None)
865876
timeout = kwargs.pop('timeout', None)
@@ -881,12 +892,11 @@ def list_blob_names(self, **kwargs: Any) -> ItemPaged[str]:
881892

882893
@distributed_trace
883894
def walk_blobs(
884-
self, name_starts_with=None, # type: Optional[str]
885-
include=None, # type: Optional[Union[List[str], str]]
886-
delimiter="/", # type: str
887-
**kwargs # type: Optional[Any]
888-
):
889-
# type: (...) -> ItemPaged[BlobProperties]
895+
self, name_starts_with: Optional[str] = None,
896+
include: Optional[Union[List[str], str]] = None,
897+
delimiter: str = "/",
898+
**kwargs: Any
899+
) -> ItemPaged[BlobProperties]:
890900
"""Returns a generator to list the blobs under the specified container.
891901
The generator will lazily follow the continuation tokens returned by
892902
the service. This operation will list blobs in accordance with a hierarchy,
@@ -914,6 +924,10 @@ def walk_blobs(
914924
:returns: An iterable (auto-paging) response of BlobProperties.
915925
:rtype: ~azure.core.paging.ItemPaged[~azure.storage.blob.BlobProperties]
916926
"""
927+
if kwargs.pop('prefix', None):
928+
raise ValueError("Passing 'prefix' has no effect on filtering, " +
929+
"please use the 'name_starts_with' parameter instead.")
930+
917931
if include and not isinstance(include, list):
918932
include = [include]
919933

sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,11 @@ async def set_container_access_policy(
647647
process_storage_error(error)
648648

649649
@distributed_trace
650-
def list_blobs(self, name_starts_with=None, include=None, **kwargs):
651-
# type: (Optional[str], Optional[Union[str, List[str]]], **Any) -> AsyncItemPaged[BlobProperties]
650+
def list_blobs(
651+
self, name_starts_with: Optional[str] = None,
652+
include: Optional[Union[str, List[str]]] = None,
653+
**kwargs: Any
654+
) -> AsyncItemPaged[BlobProperties]:
652655
"""Returns a generator to list the blobs under the specified container.
653656
The generator will lazily follow the continuation tokens returned by
654657
the service.
@@ -679,6 +682,10 @@ def list_blobs(self, name_starts_with=None, include=None, **kwargs):
679682
:dedent: 12
680683
:caption: List the blobs in the container.
681684
"""
685+
if kwargs.pop('prefix', None):
686+
raise ValueError("Passing 'prefix' has no effect on filtering, " +
687+
"please use the 'name_starts_with' parameter instead.")
688+
682689
if include and not isinstance(include, list):
683690
include = [include]
684691

@@ -718,6 +725,10 @@ def list_blob_names(self, **kwargs: Any) -> AsyncItemPaged[str]:
718725
:returns: An iterable (auto-paging) response of blob names as strings.
719726
:rtype: ~azure.core.async_paging.AsyncItemPaged[str]
720727
"""
728+
if kwargs.pop('prefix', None):
729+
raise ValueError("Passing 'prefix' has no effect on filtering, " +
730+
"please use the 'name_starts_with' parameter instead.")
731+
721732
name_starts_with = kwargs.pop('name_starts_with', None)
722733
results_per_page = kwargs.pop('results_per_page', None)
723734
timeout = kwargs.pop('timeout', None)
@@ -739,12 +750,11 @@ def list_blob_names(self, **kwargs: Any) -> AsyncItemPaged[str]:
739750

740751
@distributed_trace
741752
def walk_blobs(
742-
self, name_starts_with=None, # type: Optional[str]
743-
include=None, # type: Optional[Union[List[str], str]]
744-
delimiter="/", # type: str
745-
**kwargs # type: Optional[Any]
746-
):
747-
# type: (...) -> AsyncItemPaged[BlobProperties]
753+
self, name_starts_with: Optional[str] = None,
754+
include: Optional[Union[List[str], str]] = None,
755+
delimiter: str = "/",
756+
**kwargs: Any
757+
) -> AsyncItemPaged[BlobProperties]:
748758
"""Returns a generator to list the blobs under the specified container.
749759
The generator will lazily follow the continuation tokens returned by
750760
the service. This operation will list blobs in accordance with a hierarchy,
@@ -772,6 +782,10 @@ def walk_blobs(
772782
:returns: An iterable (auto-paging) response of BlobProperties.
773783
:rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.storage.blob.BlobProperties]
774784
"""
785+
if kwargs.pop('prefix', None):
786+
raise ValueError("Passing 'prefix' has no effect on filtering, " +
787+
"please use the 'name_starts_with' parameter instead.")
788+
775789
if include and not isinstance(include, list):
776790
include = [include]
777791

0 commit comments

Comments
 (0)