-
Notifications
You must be signed in to change notification settings - Fork 64
Description
In this diskussion we have been asked to report a bug on the db2 dialect driver side for SQL Alchemy.
I am not sure, if this is the right place. Please let me know if not.
Here the original issue: sqlalchemy/sqlalchemy#12985
The following code produces a TypeError when reading an empty db2 table. The expected result would be an empty resultset with zero rows. It looks like a null Object is returned instead.
Additional information: we upgraded from python 3.11 to python 3.13 and from sqlAlchemy 3.0.25 to 3.0.44 (latest). The hole stuff worked under 3.11+3.0.25 -> or lets say we didn't get the error there.
What is the problem:
sql = """
SELECT *
FROM table1
"""
with engine.connect() as conn:
rows = conn.execute(sa.text(sql)).all() -> This row causes the error
for row in rows:
print(row)
Here is the error message:
TypeError Traceback (most recent call last)
Cell In[8], line 8
3 sql = """
4 SELECT *
5 FROM table1
6 """
7 with engine.connect() as conn:
----> 8 rows = conn.execute(sa.text(sql)).all()
9 for row in rows:
10 print(row)
File ....venv\Lib\site-packages\sqlalchemy\engine\result.py:1384, in Result.all(self)
1367 def all(self) -> Sequence[Row[_TP]]:
1368 """Return all rows in a sequence.
1369
1370 Closes the result set after invocation. Subsequent invocations
(...) 1381
1382 """
-> 1384 return self._allrows()
File .....venv\Lib\site-packages\sqlalchemy\engine\result.py:551, in ResultInternal._allrows(self)
549 made_rows: List[_InterimRowType[_R]]
550 if make_row:
--> 551 made_rows = [make_row(row) for row in rows]
552 else:
553 made_rows = rows # type: ignore
TypeError: 'NoneType' object is not iterable
We tried to wrap the line with a try/catch to handle the error. Unfortunately in polimorphic relationships we get the same error without the possibility catching the error.
After inserting one row to the database. Everything works fine.
However when we use a where clause to remove this one row (another workaround) we still get this error when zero rows should be returned.