Skip to content

Commit 7c4b5d8

Browse files
authored
SNOW-2355815: fix index out of range (#2618)
* SNOW-2355815: fix index out of range * SNOW-2355815: update release notes
1 parent 873505d commit 7c4b5d8

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
## New additions
2222

2323
## Fixes and improvements
24+
* Fixed `snow spcs logs` `IndexOutOfRange` error
2425

2526

2627
# v3.12.0

src/snowflake/cli/_plugins/spcs/services/manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ def stream_logs(
313313

314314
if new_log_records:
315315
dedup_log_records = new_logs_only(prev_log_records, new_log_records)
316-
for log in dedup_log_records:
317-
yield filter_log_timestamp(log, include_timestamps)
316+
if dedup_log_records:
317+
for log in dedup_log_records:
318+
yield filter_log_timestamp(log, include_timestamps)
318319

319-
prev_timestamp = dedup_log_records[-1].split(" ", 1)[0]
320-
prev_log_records = dedup_log_records
320+
prev_timestamp = dedup_log_records[-1].split(" ", 1)[0]
321+
prev_log_records = dedup_log_records
321322

322323
time.sleep(interval_seconds)
323324

tests/spcs/__snapshots__/test_compute_pool.ambr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@
2929

3030
'''
3131
# ---
32-
# name: test_deploy_from_project_definition_replace
33-
'''
34-
+---------------------------------------------------------------+
35-
| key | value |
36-
|--------+------------------------------------------------------|
37-
| status | Compute pool TEST_COMPUTE_POOL successfully created. |
38-
+---------------------------------------------------------------+
39-
40-
'''
41-
# ---
4232
# name: test_deploy_from_project_definition_with_upgrade
4333
'''
4434
+-------------------------------------------+

tests/spcs/__snapshots__/test_services.ambr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@
5757

5858
'''
5959
# ---
60-
# name: test_deploy_service_replace
61-
'''
62-
+-----------------------------------------------------+
63-
| key | value |
64-
|--------+--------------------------------------------|
65-
| status | Service TEST_SERVICE successfully created. |
66-
+-----------------------------------------------------+
67-
68-
'''
69-
# ---
7060
# name: test_deploy_service_with_upgrade
7161
'''
7262
+--------------------------------------------+

tests/spcs/test_services.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,34 @@ def test_stream_logs_with_include_timestamps_true(mock_sleep, mock_logs):
892892
mock_sleep.assert_has_calls([call(interval_seconds), call(interval_seconds)])
893893

894894

895+
def test_new_logs_only_returns_empty_when_all_logs_duplicated():
896+
"""Test that new_logs_only returns empty list when all new logs are duplicates."""
897+
from snowflake.cli._plugins.spcs.common import new_logs_only
898+
899+
prev_log_records = ["2024-10-22T01:12:28Z previous log"]
900+
new_log_records = ["2024-10-22T01:12:28Z previous log"] # Same log, will be deduped
901+
902+
dedup_log_records = new_logs_only(prev_log_records, new_log_records)
903+
assert dedup_log_records == []
904+
905+
906+
def test_empty_dedup_log_records_does_not_cause_index_error():
907+
"""Test that the fix prevents IndexError when dedup_log_records is empty.
908+
909+
This test verifies that the original bug (IndexError when accessing
910+
dedup_log_records[-1] on an empty list) has been fixed.
911+
"""
912+
dedup_log_records = []
913+
914+
has_logs = bool(dedup_log_records)
915+
assert not has_logs
916+
917+
assert len(dedup_log_records) == 0
918+
919+
with pytest.raises(IndexError):
920+
dedup_log_records[-1]
921+
922+
895923
@patch(EXECUTE_QUERY)
896924
def test_logs_incompatible_flags(
897925
mock_execute_query, runner, enable_events_and_metrics_config

0 commit comments

Comments
 (0)