DataTable auto-height row with a zero-width cell raises `IndexError`

Abierto Apto para principiantes
#6,769 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
cli

Línea de trabajo

El fallo está en _update_dimensions en textual/widgets/_data_table.py, donde se lee cell_renderable[0][0].style para una celda que no renderiza segmentos. Empieza por el bucle de relleno allí y revisa cómo es el respaldo de estilo de fila. Ejecuta el fragmento con una primera columna de ancho cero y una segunda columna de dos líneas; está terminado cuando la fila se renderiza en dos líneas con la columna A vacía y sin IndexError.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Hi! I hit this while writing generated tests against Textual's widgets. In a row added with height=None, if one cell renders zero cells wide and another cell is taller, the table crashes when it measures the row.

from textual.app import App, ComposeResult
from textual.widgets import DataTable

class AutoHeightApp(App):
    def compose(self) -> ComposeResult:
        yield DataTable(cell_padding=0)

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_column("A", width=0)
        table.add_column("B")
        table.add_row("x", "two\nlines", height=None)

if __name__ == "__main__":
    AutoHeightApp().run()

Expected: a two-line row, with column A empty.

Actual (on Textual 8.2.7, and main at 5e5b7ef):

  File "textual/widgets/_data_table.py", line 1891, in _on_idle
    self._update_dimensions(new_rows)
  File "textual/widgets/_data_table.py", line 1496, in _update_dimensions
    first_line_space_style = cell_renderable[0][0].style
IndexError: list index out of range

When a cell is shorter than the row, _update_dimensions pads it with blank lines styled like its first segment. A zero-width cell renders no segments, so cell_renderable[0][0] doesn't exist.

I'd suggest falling back to the row style when the cell rendered nothing. I'm happy to send a PR.

Lenguaje dominante
Python
Estrellas
37.7k
Forks
1.5k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Textualize/textual

Todos los issues de Textualize/textual

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.