Skip to content

Bug Report: featchall() throws TypeError, when query result returns no rows #1033

@Diadochokinetic

Description

@Diadochokinetic
  • Operating System Name: Ubuntu 22.04

  • db2level output from clidriver if in use: DB21085I This instance or install (instance name, where applicable:
    "db2inst1") uses "64" bits and DB2 code release "SQL12010" with level
    identifier "02010110".
    Informational tokens are "DB2 v12.1.0.0", "special_50594",
    "DYN2411071022AMD64_50594", and Fix Pack "0".
    Product is installed at "/opt/ibm/db2/V12.1".

  • Target Db2 Server Version: DB2 v12.1.0.0

  • Python Version: 3.10.15

  • ibm_db version: 3.2.7

  • For non-Windows, output of below commands:
    uname: Linux
    uname -m: x86_64

  • Value of below environment variables if set:
    IBM_DB_HOME: /home/db2inst1/sqllib
    PATH: /home/db2inst1/miniforge-pypy3/envs/pandas-db2/bin:/home/db2inst1/miniforge-pypy3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/misc:/home/db2inst1/sqllib/pd:/home/db2inst1/sqllib/gskit/bin:/home/db2inst1/sqllib/db2tss/bin
    LIB/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH:

  • Test script to reproduce the problem.

  • For installation related issue, complete output of pip install ibm_db command.

Steps to Reproduce:

from sqlalchemy import create_engine, text
db2 = create_engine("ibm_db_sa://db2inst1:password@localhost:25000/sample")
with db2.begin() as conn:
    result = conn.execute(text("SELECT CID FROM DB2INST1.CUSTOMER WHERE CID > 2000"))
    print(result.fetchall())

In versions below 3.2.7, e.g. 3.2.6 the print shows an empty list, which is the expected result. In version 3.2.7 the execution yields the follow exception:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 3
      1 with db2.begin() as conn:
      2     result = conn.execute(text("SELECT CID FROM DB2INST1.CUSTOMER WHERE CID > 2000"))
----> 3     print(result.fetchall())

File [~/miniforge-pypy3/envs/pandas-db2/lib/python3.10/site-packages/sqlalchemy/engine/result.py:1317](http://127.0.0.1:8888/lab/tree/Projects/miniforge-pypy3/envs/pandas-db2/lib/python3.10/site-packages/sqlalchemy/engine/result.py#line=1316), in Result.fetchall(self)
   1314 def fetchall(self) -> Sequence[Row[_TP]]:
   1315     """A synonym for the :meth:`_engine.Result.all` method."""
-> 1317     return self._allrows()

File [~/miniforge-pypy3/envs/pandas-db2/lib/python3.10/site-packages/sqlalchemy/engine/result.py:551](http://127.0.0.1:8888/lab/tree/Projects/miniforge-pypy3/envs/pandas-db2/lib/python3.10/site-packages/sqlalchemy/engine/result.py#line=550), 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions