Skip to content

Commit 03f51ca

Browse files
authored
fix: handle empty buckets (#152)
* fix: handle empty buckets * fix:update json file with new page response with no CommonPrefixes; updateunit tes with new expected empty list * fix: remove NextContinuationToken and set IsTruncated to false
1 parent 0e81e78 commit 03f51ca

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

.flake8

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[flake8]
2+
3+
exclude =
4+
.git,
5+
__pycache__,
6+
build,
7+
.venv,
8+
venv,
9+
.conda
10+
max-complexity = 10
11+

src/aind_data_asset_indexer/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def iterate_through_top_level(
452452
for page in pages:
453453
yield [
454454
p.get("Prefix")
455-
for p in page["CommonPrefixes"]
455+
for p in page.get("CommonPrefixes", [])
456456
if p.get("Prefix") is not None
457457
]
458458

tests/resources/utils/example_pages_response.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,29 @@
101101
"EncodingType": "url",
102102
"KeyCount": 1,
103103
"ContinuationToken": "1GQ5"
104+
},
105+
{
106+
"ResponseMetadata": {
107+
"RequestId": "RequestId",
108+
"HostId": "HostId",
109+
"HTTPStatusCode": 200,
110+
"HTTPHeaders": {
111+
"x-amz-id-2": "x-amz-id-2",
112+
"x-amz-request-id": "x-amz-request-id",
113+
"date": "Mon, 13 May 2024 21:22:24 GMT",
114+
"x-amz-bucket-region": "us-west-2",
115+
"content-type": "application/xml",
116+
"transfer-encoding": "chunked",
117+
"server": "AmazonS3"
118+
},
119+
"RetryAttempts": 0
120+
},
121+
"IsTruncated": false,
122+
"Name": "aind-ephys-data-dev-u5u0i5",
123+
"Prefix": "",
124+
"Delimiter": "/",
125+
"MaxKeys": 3,
126+
"EncodingType": "url",
127+
"KeyCount": 3
104128
}
105129
]

tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ def test_iterate_through_top_level(self, mock_s3_client):
589589
"ecephys_655019_2000-01-01_01-01-02/",
590590
],
591591
["ecephys_684156_2000-01-01_00-00-01/"],
592+
[],
592593
]
593594

594595
self.assertEqual(expected_output, list(output))

0 commit comments

Comments
 (0)