fix: prevent KeyError when clearing and re-rendering DataTable#6591
Open
xbrxr03 wants to merge 1 commit into
Open
fix: prevent KeyError when clearing and re-rendering DataTable#6591xbrxr03 wants to merge 1 commit into
xbrxr03 wants to merge 1 commit into
Conversation
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
Fixes #4900
DataTable.clear()was not clearing_updated_cellsand_new_rows, leaving staleRowKeyreferences that could cause aKeyErrorwhen the table was re-rendered after clearing and adding new rows.Root Cause
When
DataTable.clear()is called, it clearsself.rows,self._data, andself._row_locations, but it does not clearself._updated_cellsorself._new_rows. These sets retain staleRowKey/CellKeyobjects that reference rows which no longer exist in the table.Since
RowKey(value=None)usesid(self)as its hash, these stale key objects will never match any key in the rebuiltself.rowsdict. When theon_idlehandler processes these stale references, it can trigger aKeyErrorin code paths that accessself.rows[row_key]directly (without.get()).Notably,
remove_row()already cleans up_updated_cellsfor the removed row —clear()should do the same for all rows.Fix
Add two lines to
DataTable.clear()to clear the stale reference sets:Test
Added
test_clear_clears_updated_cells_and_new_rowswhich verifies that both_updated_cellsand_new_rowsare empty after callingclear().Checklist