Reject out-of-range column index in Dataset.add_formatter - #679
Open
uttam12331 wants to merge 1 commit into
Open
Reject out-of-range column index in Dataset.add_formatter#679uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
Columns are 0-indexed, so the last valid index is `width - 1`. The bounds check used `col <= self.width`, which accepts `col == width` (one past the last column). That out-of-range index was silently stored and then raised `IndexError: list index out of range` later, deep in export/format_row, instead of the intended `InvalidDatasetIndex` at the `add_formatter` call site. Use `col < self.width`, and add a regression test for the boundary.
|
#655 is the same fix, opened six weeks earlier (2026-07-10). Identical hunk in The difference worth keeping is in this PR's test. It asserts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dataset.add_formatteraccepts a column index one past the last column, then crashes later on export instead of rejecting it up front.Columns are 0-indexed everywhere (
get_col(index)→row[index], formatter application →row[col] = handler(row[col])), so the maximum valid index iswidth - 1. But the bounds check uses<=:The
else: raise InvalidDatasetIndexbranch shows the intent is to reject out-of-range indices — the boundary is just off by one.Reproduction
Expected:
add_formatter(2, ...)should raiseInvalidDatasetIndexat the call site.Fix
Tests
Added
test_add_formatter_out_of_range_column: on a width-3 dataset it confirms the last valid index (2) is accepted and index 3 raisesInvalidDatasetIndex. It fails on the current code (silently accepted) and passes with the fix; the existing formatter tests still pass.