Skip to content

Commit

Permalink
Merge branch 'main' into fix-listview-fix-remove-items
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan authored Jul 15, 2024
2 parents 04f7c89 + b50e697 commit d87375c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- `TextArea.line_number_start` reactive attribute https://github.com/Textualize/textual/pull/4471
- `Widget.remove_children` now accepts an iterable if widgets in addition to a selector https://github.com/Textualize/textual/issues/4735
- Raise `ValueError` with improved error message when number of cells inserted using `DataTable.add_row` doesn't match the number of columns in the table https://github.com/Textualize/textual/pull/4742

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,9 @@ def add_row(
# If we don't do this, users will be required to call add_column(s)
# Before they call add_row.

if len(cells) > len(self.ordered_columns):
raise ValueError("More values provided than there are columns.")

row_index = self.row_count
# Map the key of this row to its current index
self._row_locations[row_key] = row_index
Expand Down
8 changes: 8 additions & 0 deletions tests/test_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ async def test_add_row_duplicate_key():
with pytest.raises(DuplicateKey):
table.add_row("2", key="1") # Duplicate row key

async def test_add_row_too_many_values():
app = DataTableApp()
async with app.run_test():
table = app.query_one(DataTable)
table.add_column("A")
table.add_row("1", key="1")
with pytest.raises(ValueError):
table.add_row("1", "2")

async def test_add_column_duplicate_key():
app = DataTableApp()
Expand Down

0 comments on commit d87375c

Please sign in to comment.