DataTable raises `KeyError: None` when `fixed_rows` is larger than the number of rows
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Il crash ha origine in render_line in textual/widgets/_data_table.py, che costruisce le chiavi delle righe fisse a partire da self._row_locations.get_key(row_index); questo restituisce None oltre l’ultima riga, e quindi get_row_height non riesce ad accedere a self.rows[None]. Confrontalo con _get_fixed_offset, che usa già ordered_rows[: self.fixed_rows], e riproduci il problema con lo snippet nell’issue (una DataTable vuota con fixed_rows=1). Il lavoro è completo quando i casi di tabella vuota e corta mostrano l’intestazione senza un KeyError e un test di regressione copre il caso in cui fixed_rows è maggiore del numero di righe.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Textual's widgets. A DataTable with fixed_rows set crashes on its first render if it has fewer rows than that, which includes the common case of an empty table whose rows are loaded later.
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class FixedRowsApp(App):
def compose(self) -> ComposeResult:
yield DataTable(fixed_rows=1)
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns("A", "B")
# Rows will be loaded later.
if __name__ == "__main__":
FixedRowsApp().run()
Expected: an empty table with its header.
Actual (on Textual 8.2.7, and main at 5e5b7ef):
File "textual/widgets/_data_table.py", line 2487, in render_line
fixed_rows_height = sum(
self.get_row_height(row_key) for row_key in fixed_row_keys
)
File "textual/widgets/_data_table.py", line 2488, in <genexpr>
self.get_row_height(row_key) for row_key in fixed_row_keys
File "textual/widgets/_data_table.py", line 1121, in get_row_height
return self.rows[row_key].height
KeyError: None
render_line builds the fixed row keys with self._row_locations.get_key(row_index) for row_index in range(self.fixed_rows), and get_key returns None for an index past the last row. The same happens with fixed_rows=3 and one row. _get_fixed_offset already slices ordered_rows[: self.fixed_rows], so it copes; only render_line doesn't.
I'd suggest clamping to the row count in render_line. I'm happy to send a PR with a test.
- Lingua principale
- Python
- Stelle
- 37.7k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/textual
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6790 · 2 commenti ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Textualize/textual#6789 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6787 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6782 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Textualize/textual#6778 · 1 commento ·
Tutte le issue di Textualize/textual
Issue simili
-
Internal ErrorApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
frappe/frappe_docker#2071 ·
I maintainer di solito rispondono entro 1 giorno
-
bug python
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
traceloop/openllmetry#4717 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Apertacomp/desktop P2 type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#157702 ·
I maintainer di solito rispondono entro 1 giorno
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenForse già presa @BahaaMattar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
I maintainer di solito rispondono entro 1 giorno