Skip to content

fix(data-editor): don't crash appending a row to an empty row-oriented editor - #10651

Draft
winklemad wants to merge 1 commit into
marimo-team:mainfrom
winklemad:fix/data-editor-empty-append
Draft

fix(data-editor): don't crash appending a row to an empty row-oriented editor#10651
winklemad wants to merge 1 commit into
marimo-team:mainfrom
winklemad:fix/data-editor-empty-append

Conversation

@winklemad

Copy link
Copy Markdown
Contributor

This pull request was authored by a coding agent.

📝 Summary

Closes #10650

_apply_positional_edit_row_oriented crashed with IndexError when appending a new row to an empty row-oriented editor: it built the new row from data[0], which raises on an empty list. This is reachable from the UI by deleting all rows and then adding one.

When there is no existing row to read column names from, this falls back to the editor's schema (and always includes the edited column), so appending the first row works. The column-oriented path already handled the empty case.

📋 Pre-Review Checklist

  • I have discussed large / public-API changes via an issue — n/a, small bug fix.
  • Any AI-generated code has been reviewed line-by-line by me and I stand by it.

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation/docstrings updated where applicable.
  • Tests added (empty-append + remove-all-then-add replay).

…d editor

Appending a positional edit to an empty row-oriented data editor raised
IndexError because the new row's columns were read from data[0], which
does not exist when there are no rows yet. Derive the columns from the
schema when available and always include the edited column, mirroring the
column-oriented path. This also fixes the remove-all-then-add edit replay.
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview Aug 25, 2026 8:56am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash when appending the first row in an empty row-oriented data editor.

Changes:

  • Adds fallback logic for empty row-oriented appends.
  • Adds regression tests for empty and remove-all-then-add scenarios.
  • Critical issue: replay via _convert_value can still drop existing columns because no schema is preserved or passed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Summary
tests/_plugins/ui/_impl/test_data_editor.py Adds regression coverage for empty-row appends.
marimo/_plugins/ui/_impl/data_editor.py Updates empty-row append handling; requires preserving or passing the original editor schema and testing _convert_value.
Suppressed comments (3)

marimo/_plugins/ui/_impl/data_editor.py:471

  • This still appends only one row for every rowIdx >= len(data). For example, an empty row-oriented input with rowIdx: 1 reaches data[1] after this append and raises IndexError; the column-oriented path extends through the requested index. Extend by rowIdx - len(data) + 1 rows (or reject non-contiguous indices) so the guarded branch is correct for all out-of-range positional edits.
        new_row: dict[str, Any] = {col: None for col in columns}
        new_row.setdefault(edit["columnId"], None)
        data.append(new_row)

marimo/_plugins/ui/_impl/data_editor.py:471

  • This fallback only adds the column from the first edit. If one edit batch contains multiple cells for the first new row, the next column enters the existing-row path and data[0][columnId] raises KeyError. The UI's row-add replay emits one positional edit per column, so remove-all-then-add with a multi-column row still crashes; ensure the target row contains the column before reading/updating it and add that regression case.
        new_row: dict[str, Any] = {col: None for col in columns}
        new_row.setdefault(edit["columnId"], None)
        data.append(new_row)

marimo/_plugins/ui/_impl/data_editor.py:466

  • nw.Schema exposes its column names through names() (as used elsewhere in this codebase), not keys(). This makes the new schema fallback raise AttributeError before appending, so the added _with_schema regression test fails; use schema.names() here.
            columns = list(schema.keys())

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +465 to +466
elif schema is not None:
columns = list(schema.keys())
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.

data_editor: IndexError appending a row to an empty row-oriented editor

2 participants