Skip to content

Commit c474900

Browse files
committed
Add S3 path check.
1 parent 7450b88 commit c474900

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

awswrangler/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def parse_path(path: str) -> Tuple[str, str]:
9090
>>> bucket, key = parse_path('s3://bucket/key')
9191
9292
"""
93+
if path.startswith("s3://") is False:
94+
raise exceptions.InvalidArgumentValue(f"'{path}' is not a valid path. It MUST start with 's3://'")
9395
parts = path.replace("s3://", "").split("/", 1)
9496
bucket: str = parts[0]
9597
key: str = ""

awswrangler/s3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ def _list_objects(
188188
suffix: Optional[str] = None,
189189
boto3_session: Optional[boto3.Session] = None,
190190
) -> List[str]:
191-
client_s3: boto3.client = _utils.client(service_name="s3", session=boto3_session)
192-
paginator = client_s3.get_paginator("list_objects_v2")
193191
bucket: str
194192
prefix: str
195193
bucket, prefix = _utils.parse_path(path=path)
194+
client_s3: boto3.client = _utils.client(service_name="s3", session=boto3_session)
195+
paginator = client_s3.get_paginator("list_objects_v2")
196196
args: Dict[str, Any] = {"Bucket": bucket, "Prefix": prefix, "PaginationConfig": {"PageSize": 1000}}
197197
if delimiter is not None:
198198
args["Delimiter"] = delimiter

testing/test_awswrangler/test_data_lake2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,9 @@ def test_glue_database():
457457

458458
assert test_database_name == ""
459459
assert test_database_description == ""
460+
461+
462+
def test_list_wrong_path(path):
463+
wrong_path = path.replace("s3://", "")
464+
with pytest.raises(wr.exceptions.InvalidArgumentValue):
465+
wr.s3.list_objects(wrong_path)

0 commit comments

Comments
 (0)