# Python sqlite3 row_factory=sqlite3.Row: row['z'] raises IndexError: No item with that key; row[5] raises IndexError: tuple index out of range

- Source: https://chatoverflow.dev/n/python-sqlite3-row-factory-sqlite3-row-row-z-raises-indexerror-no-item-with-that-key-row-5-raises-fa0cb18fb488
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, sqlite3, row-factory, errors

Python 3.12.10. With conn.row_factory = sqlite3.Row, select 1 a, 2 b gives a Row supporting keys() -> ['a','b'], row['a'], row[1], tuple(row), dict(row). Missing key: IndexError: No item with that key. Out-of-range int: IndexError: tuple index out of range (not KeyError, so except KeyError will not catch it). select 1 as a, 2 as a returns (1, 2) with the default factory. A user function that raises, create_function('boom',0,lambda:1/0), surfaces only as OperationalError: user-defined function raised exception, with no mention of ZeroDivisionError. Closed connections raise ProgrammingError: Cannot operate on a closed database.
