Skip to content

Initialize all columns when appending rows to data_editor#13916

Merged
lukasmasuch merged 3 commits intodevelopfrom
lukasmasuch/fix-issue-13915
Feb 12, 2026
Merged

Initialize all columns when appending rows to data_editor#13916
lukasmasuch merged 3 commits intodevelopfrom
lukasmasuch/fix-issue-13915

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

Describe your changes

When a user adds a row to a data_editor with num_rows='dynamic' and then shows a previously hidden column (like the index column) via the "show/hide columns" menu, the app crashes with "No cell found for an added row" error.

Root cause: Cells were only initialized for currently visible columns when a row was added. When hidden columns were later made visible, the cells for those columns didn't exist, causing the error.

Fix: Initialize cells for all columns (including hidden ones) when a new row is appended. This is achieved by using allColumns instead of columns in the appendEmptyRow function.

GitHub Issue Link

Fixes #13915

Testing Plan


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

…editor

When a user adds a row to a data_editor with num_rows='dynamic', cells were only
created for currently visible columns. If the index column was hidden when adding
the row, no cell was created for it. Later, when showing the hidden column via the
"show/hide columns" menu, the code tried to access the cell but it didn't exist,
causing the error "No cell found for an added row".

The fix ensures cells are initialized for all columns (including hidden ones) when
a new row is added. This allows columns to be shown/hidden without errors.

Changes:
- useDataEditor: Use allColumns instead of columns when initializing new rows
- DataFrame: Pass allColumns parameter to useDataEditor
- Tests: Updated all test cases and added a new test for this specific scenario
Copilot AI review requested due to automatic review settings February 11, 2026 18:05
@lukasmasuch lukasmasuch changed the title Fix issue #13915: Initialize all columns when appending rows to data_editor Initialize all columns when appending rows to data_editor Feb 11, 2026
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Feb 11, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@lukasmasuch lukasmasuch added security-assessment-completed change:bugfix PR contains bug fix implementation impact:users PR changes affect end users ai-review If applied to PR or issue will run AI review workflow labels Feb 11, 2026
@lukasmasuch
Copy link
Copy Markdown
Collaborator Author

@cursor review

@lukasmasuch lukasmasuch changed the title Initialize all columns when appending rows to data_editor Initialize all columns when appending rows to data_editor Feb 11, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 11, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13916/streamlit-1.54.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13916.streamlit.app (☁️ Deploy here if not accessible)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@github-actions github-actions bot removed the ai-review If applied to PR or issue will run AI review workflow label Feb 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Summary

This PR fixes issue #13915 where adding a row to a data_editor with num_rows='dynamic' and then revealing a previously hidden column (e.g., the index column via the show/hide columns menu) caused a crash with "No cell found for an added row."

The fix is a one-line change in useDataEditor.ts: the appendEmptyRow function now iterates over allColumns (which includes hidden columns) instead of just columns (visible columns only) when initializing cells for a new row. The allColumns prop is threaded from DataFrame.tsx into the hook, and the useCallback dependency array is updated accordingly.

Code Quality

The change is minimal, well-targeted, and follows existing patterns in the codebase:

  • useDataEditor.ts: The new allColumns parameter is properly typed in the UseDataEditorParams interface with a clear JSDoc comment (lines 51–55). The useCallback dependency array is correctly updated from columns to allColumns (line 168), ensuring the memoized callback stays fresh when allColumns changes.
  • DataFrame.tsx: The allColumns value is already available from useColumnLoader and is simply passed through to the hook (line 386). No new computation or state is introduced.
  • Test file: The new test at line 404 is well-structured, clearly documents the issue it's verifying, and sets up the hidden-column scenario correctly. All 16 existing tests are updated to include the new allColumns parameter. The test properly verifies both hidden and visible column cells are created.

No issues found with code structure or maintainability.

Test Coverage

Unit tests: A dedicated test ("creates cells for hidden columns when row is appended (issue #13915)") directly reproduces the bug scenario by:

  1. Creating a hidden column with isHidden: true and isIndex: true.
  2. Passing different columns (visible only) and allColumns (including hidden) arrays.
  3. Appending a row and verifying that cells are created for all columns, including the hidden one.

The test includes both positive assertions (cells exist for all columns) and the existing test ("allows to add new rows via onRowAppended") continues to validate the basic row-addition path.

E2E tests: No new e2e test was added. The PR mentions manual Playwright verification. Given this is a targeted internal bugfix in the data grid editing logic, the unit test coverage is adequate.

One minor gap: The test could additionally assert that no cells exist for the hidden column before the row append (negative/baseline assertion), which would strengthen the test. However, this is a very minor point and does not block approval.

Backwards Compatibility

This change is fully backwards compatible:

  • When there are no hidden columns, allColumns is identical to columns, so behavior is unchanged.
  • The allColumns prop was already available in the DataFrame component from useColumnLoader; it's simply being forwarded to useDataEditor.
  • Hidden column cells are initialized with their defaultValue (same as visible columns), so no unexpected data is introduced.
  • No public API or protobuf changes.

Security & Risk

No security concerns. The change is a low-risk bugfix:

  • It only affects the cell initialization path when new rows are appended.
  • The cells for hidden columns are initialized with the same safe column.getCell(column.defaultValue) pattern used for visible columns.
  • No new external inputs or data flows are introduced.

Accessibility

No accessibility impact. This is a data-layer fix in a React hook — no DOM elements, ARIA attributes, or keyboard interactions are affected.

Recommendations

No blocking issues. One minor suggestion:

  1. Optional test improvement: In the hidden-column test (line 404), consider adding a baseline assertion before onRowAppended() that the hidden column cell does not exist yet (e.g., expect(editingState.current.getCell(2, INITIAL_NUM_ROWS)).toBeUndefined()). This would make the test's before/after contract more explicit per the "positive + negative assertions" testing guideline.

Verdict

APPROVED: Clean, minimal, and well-tested bugfix that correctly initializes cells for hidden columns when appending rows, preventing a crash when those columns are later made visible.


This is an automated AI review by opus-4.6-thinking.

columns.forEach(column => {
// We use allColumns (including hidden columns) to ensure that
// cells are created for all columns. This prevents issues when
// a hidden column is later made visible.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could consider linking back to the original bug report in the comments for more context: #13916

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

- Add baseline assertion in test to verify row count before onRowAppended()
- Add reference to issue #13915 in code comment for better context
@lukasmasuch lukasmasuch enabled auto-merge (squash) February 12, 2026 17:31
@lukasmasuch lukasmasuch merged commit 1146ce9 into develop Feb 12, 2026
41 of 43 checks passed
@lukasmasuch lukasmasuch deleted the lukasmasuch/fix-issue-13915 branch February 12, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

3 participants