Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 01398f4

Browse files
authored
Fix #1489: fix crash when bundles does not exist yet (#1491)
1 parent da7af1c commit 01398f4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

commands/build_bundles.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ def fetch_all_changesets(client):
5353

5454

5555
@retry_timeout
56-
def get_modified_timestamp(url):
56+
def get_modified_timestamp(url) -> int:
5757
"""
5858
Return URL modified date as epoch millisecond.
5959
"""
6060
resp = requests.get(url)
6161
if not resp.ok:
62-
return None
62+
filename = url.split("/")[-1]
63+
print(f"No previous '{filename}' bundle found") # happens on first run.
64+
return -1
6365
dts = resp.headers["Last-Modified"]
6466
dt = parsedate_to_datetime(dts)
6567
epoch_msec = int(dt.timestamp() * 1000)
@@ -193,9 +195,6 @@ def build_bundles(event, context):
193195
existing_bundle_timestamp = get_modified_timestamp(
194196
f"{base_url}{DESTINATION_FOLDER}/changesets.zip"
195197
)
196-
if existing_bundle_timestamp is None:
197-
print("No previous 'changesets.zip' bundle found") # Should only happen once.
198-
existing_bundle_timestamp = -1
199198
print(f"'changesets.zip' was published at {existing_bundle_timestamp}")
200199
if BUILD_ALL or (existing_bundle_timestamp < highest_timestamp):
201200
write_zip(
@@ -216,9 +215,6 @@ def build_bundles(event, context):
216215
existing_bundle_timestamp = get_modified_timestamp(
217216
f"{base_url}{DESTINATION_FOLDER}/startup.zip"
218217
)
219-
if existing_bundle_timestamp is None:
220-
print("No previous 'startup.zip' bundle found") # Should only happen once.
221-
existing_bundle_timestamp = -1
222218
print(f"'startup.zip' was published at {existing_bundle_timestamp}")
223219
if BUILD_ALL or existing_bundle_timestamp < highest_timestamp:
224220
write_zip(

tests/test_build_bundles.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_get_modified_timestamp_missing():
122122
url = "http://example.com/file"
123123
responses.add(responses.GET, url, status=404)
124124
timestamp = get_modified_timestamp(url)
125-
assert timestamp is None
125+
assert timestamp == -1
126126

127127

128128
def test_write_zip(tmpdir):
@@ -201,7 +201,17 @@ def test_build_bundles(mock_fetch_all_changesets, mock_write_zip, mock_sync_clou
201201
"metadata": {"id": "collection5", "bucket": "bucket5", "flags": ["startup"]},
202202
"timestamp": 1720004688000 + 10,
203203
},
204+
{ # collection newly marked as bundled
205+
"changes": [{"id": "record5"}],
206+
"metadata": {"id": "collection6", "bucket": "bucket6", "attachment": {"bundle": True}},
207+
"timestamp": 1720004688000 + 10,
208+
},
204209
]
210+
responses.add(
211+
responses.GET,
212+
f"{server_url}/attachments/bundles/bucket6--collection6.zip",
213+
status=404,
214+
)
205215

206216
build_bundles(event, context={})
207217

@@ -221,7 +231,7 @@ def test_build_bundles(mock_fetch_all_changesets, mock_write_zip, mock_sync_clou
221231
# Assert the second call (changesets.zip)
222232
changesets_zip_path, changesets_zip_files = calls[1][0]
223233
assert changesets_zip_path == "changesets.zip"
224-
assert len(changesets_zip_files) == 6
234+
assert len(changesets_zip_files) == 7
225235
assert changesets_zip_files[0][0] == "bucket0--collection0.json"
226236
assert changesets_zip_files[1][0] == "bucket1--collection1.json"
227237
assert changesets_zip_files[2][0] == "bucket2--collection2.json"
@@ -247,6 +257,7 @@ def test_build_bundles(mock_fetch_all_changesets, mock_write_zip, mock_sync_clou
247257
"bucket2--collection2.zip",
248258
"bucket3--collection3.zip",
249259
"bucket5--collection5.zip",
260+
"bucket6--collection6.zip",
250261
],
251262
)
252263

0 commit comments

Comments
 (0)