From 6ce6a2db7a7747be9c34c8e2fa1496a2c658f670 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 18 Feb 2025 11:54:35 +0100 Subject: [PATCH] For reading DbData tables, add check for DbData._cols equal in number to encountered row columns. --- src/ytplom/db.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ytplom/db.py b/src/ytplom/db.py index 3bf7198..45af7cf 100644 --- a/src/ytplom/db.py +++ b/src/ytplom/db.py @@ -111,6 +111,12 @@ class DbData: @classmethod def _from_table_row(cls, row: SqlRow) -> Self: + n_cols_row, n_cols_class = len(row), len(cls._cols) + if n_cols_row != n_cols_class: + raise HandledException( + 'Trouble reading table row for {cls.__name__}: number of row ' + f'columns ({n_cols_row}) unequal number expected by class ' + f'({n_cols_class}). Maybe DB schema wrong/unmigrated?') kwargs = {} for i, col_name in enumerate(cls._cols): kwargs[col_name] = row[i] -- 2.30.2