Skip to content

python/adbc_driver_manager: executemany requires argument of positive length in 1.7.0 #3319

@avm19

Description

@avm19

What happened?

Starting from 1.7.0, cursor.executemany(operation, seq_of_parameters) throws adbc_driver_manager.ProgrammingError: INVALID_ARGUMENT: [libpq] Failed to execute query ... when seq_of_parameters has length 0, e.g. an empty list.

This is not such a big deal, but annoying, as did not have to worry about this edge case in previous versions. I checked release notes and found no mention of this change. I assume, this was unintentional and hence a bug.

Stack Trace

Traceback (most recent call last):
  File "....bug_adbc_executemany_empty.py", line 17, in <module>
    cursor.executemany(
    ~~~~~~~~~~~~~~~~~~^
        "INSERT INTO test1 (id, val) VALUES ($1, $2);",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        [],  # FAILS IN 1.7.0 but works in 1.5.0
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File ".../lib/python3.13/site-packages/adbc_driver_manager/dbapi.py", line 771, in executemany
    self._rowcount = _blocking_call(
                     ~~~~~~~~~~~~~~^
        self._stmt.execute_update, (), {}, self._stmt.cancel
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "adbc_driver_manager/_lib.pyx", line 1674, in adbc_driver_manager._lib._blocking_call_impl
  File "adbc_driver_manager/_lib.pyx", line 1667, in adbc_driver_manager._lib._blocking_call_impl
  File "adbc_driver_manager/_lib.pyx", line 1391, in adbc_driver_manager._lib.AdbcStatement.execute_update
  File "adbc_driver_manager/_lib.pyx", line 261, in adbc_driver_manager._lib.check_error
adbc_driver_manager.ProgrammingError: INVALID_ARGUMENT: [libpq] Failed to execute query 'INSERT INTO test1 (id, val) VALUES ($1, $2);': ERROR:  there is no parameter $1
LINE 1: INSERT INTO test1 (id, val) VALUES ($1, $2);
                                            ^
. SQLSTATE: 42P02

How can we reproduce the bug?

with adbc_driver_postgresql.dbapi.connect(uri) as conn:
    with conn.cursor() as cursor:
        cursor.execute("CREATE TEMP TABLE test1 (id INTEGER, val INTEGER);")

        # This works in 1.5.0, 1.6.0 and 1.7.0:
        cursor.executemany("INSERT INTO test1 (id, val) VALUES ($1, $2);", [(1, 1), (2, 2)])

        # This fails for adbc_driver_manager==1.7.0, but works in previous versions:
        cursor.executemany("INSERT INTO test1 (id, val) VALUES ($1, $2);", [])

Environment/Setup

I use Postgres, but this might be irrelevant, not sure.

Out of these three combinations of versions, only the last one shows the bug:

pip install "adbc-driver-manager==1.6.0" "adbc-driver-postgresql==1.7.0";
pip install "adbc-driver-manager==1.6.0" "adbc-driver-postgresql==1.6.0";
pip install "adbc-driver-manager==1.7.0" "adbc-driver-postgresql==1.6.0";

Metadata

Metadata

Assignees

Labels

Type: bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions