home · contact · privacy
For reading DbData tables, add check for DbData._cols equal in number to encountered...
authorChristian Heller <c.heller@plomlompom.de>
Tue, 18 Feb 2025 10:54:35 +0000 (11:54 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 18 Feb 2025 10:54:35 +0000 (11:54 +0100)
src/ytplom/db.py

index 3bf719863ee31a609d656e3ccaee894d34551527..45af7cf6f7446f7181c87ae98e8f2b0293bba192 100644 (file)
@@ -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]