Skip to content

Fix decompress_list IndexError on empty string input - #3356

Open
Anurag-M1 wants to merge 2 commits into
Netflix:masterfrom
Anurag-M1:fix/decompress-list-empty-string
Open

Fix decompress_list IndexError on empty string input#3356
Anurag-M1 wants to merge 2 commits into
Netflix:masterfrom
Anurag-M1:fix/decompress-list-empty-string

Conversation

@Anurag-M1

@Anurag-M1 Anurag-M1 commented Aug 30, 2026

Copy link
Copy Markdown

Summary

decompress_list("") crashes with IndexError because lststr[0] is accessed with no guard for empty input. This breaks the round-trip invariant decompress_list(compress_list([])) == [].

Context / Motivation

compress_list([]) legitimately returns "" (joining an empty list). However, decompress_list("") immediately crashes at line 387 because lststr[0] is accessed without checking for empty input first. An empty task ID list is a valid real-world state.

Fixes #3017

Changes Made

  • Added early return if lststr == "": return [] in decompress_list() before the lststr[0] access
  • Uses strict == "" (not not lststr) so None still fails loudly — if None slips through, the real bug should be caught upstream

Testing

Added test/unit/test_compress_decompress_list.py with 7 test cases:

Test What it verifies
test_compress_empty_list compress_list([]) == ""
test_decompress_empty_string decompress_list("") == [] (the actual bug)
test_roundtrip_empty decompress_list(compress_list([])) == []
test_roundtrip[single] Round-trip with ["x"]
test_roundtrip[simple] Round-trip with ["a", "b", "c"]
test_roundtrip[common-prefix] Items with shared prefix trigger : encoding
test_roundtrip_zlib Force zlib path via zlibmin=0

All 7 tests pass. Full unit test suite unaffected.

$ python3 -m pytest test/unit/test_compress_decompress_list.py -v
7 passed in 0.17s

AI Disclosure

  • I used AI tools in preparing this contribution

AI tools were used to help identify the issue and structure the PR. All code was reviewed and understood before submission.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes empty-list round trips by making decompress_list("") return an empty list before indexing the input.

  • Adds an explicit empty-string guard while preserving failure behavior for None.
  • Adds regression and round-trip coverage for empty, plain, prefix-compressed, and zlib-compressed lists.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
metaflow/util.py Adds a narrowly scoped empty-string guard that prevents the reported IndexError and restores the compression round-trip invariant.
test/unit/test_compress_decompress_list.py Adds focused regression tests for empty input and representative existing compression modes.

Reviews (3): Last reviewed commit: "Merge branch 'master' into fix/decompres..." | Re-trigger Greptile

@talsperre

Copy link
Copy Markdown
Collaborator

It makes fixes for two separate issues. Let's just do a targeted fix of #3017 and then I can run the tests/merge.

@Anurag-M1
Anurag-M1 force-pushed the fix/decompress-list-empty-string branch from d2805c2 to b379524 Compare August 31, 2026 08:34
@Anurag-M1

Copy link
Copy Markdown
Author

Updated as requested! Rebased onto master and narrowed down the PR to only include the targeted fix for #3017 along with unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: decompress_list raises IndexError on empty string input

2 participants