Broken error reporting through Python ADBC

Open
#181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, postgresql, python
Domain
api, databases

Research direction

Reproduce the query through the Python ADBC DBAPI path, starting at cur.execute and the cursor close path. Trace the Flight SQL Action::SelectPreparedStatement error and the subsequent ClosePreparedStatement handling. Done means division by zero is reported promptly without the stolen-session and cleanup errors shown in the traceback.

Written by the indexing model from the issue text.

Description

The following query should report a division by zero:

import adbc_driver_flightsql.dbapi as flight_sql

with flight_sql.connect(uri="grpc://localhost:15432",
                        db_kwargs={"username": "avogelsgesang",
                                   "adbc.flight.sql.rpc.call_header.x-flight-sql-database": "avogelsgesang"
                                   }
                        ) as conn:
   with conn.cursor() as cur:
        cur.execute("SELECT 1/0;")

However, this does not work as expected. Instead cur.execute first hangs for a couple of minutes before then reporting

Traceback (most recent call last):
  File "/home/avogelsgesang/Documents/af-query.py", line 9, in <module>
    cur.execute("SELECT 1/0;")
  File "/home/avogelsgesang/.local/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 669, in execute
    handle, self._rowcount = self._stmt.execute_query()
  File "adbc_driver_manager/_lib.pyx", line 1106, in adbc_driver_manager._lib.AdbcStatement.execute_query
  File "adbc_driver_manager/_lib.pyx", line 227, in adbc_driver_manager._lib.check_error
adbc_driver_manager.ProgrammingError: INVALID_ARGUMENT: [FlightSQL] failed to run: Action::SelectPreparedStatement: division by zero (InvalidArgument; ExecuteQuery)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/avogelsgesang/Documents/af-query.py", line 8, in <module>
    with conn.cursor() as cur:
  File "/home/avogelsgesang/.local/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 225, in __exit__
    self.close()
  File "/home/avogelsgesang/.local/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 611, in close
    self._stmt.close()
  File "adbc_driver_manager/_lib.pyx", line 1078, in adbc_driver_manager._lib.AdbcStatement.close
  File "adbc_driver_manager/_lib.pyx", line 1084, in adbc_driver_manager._lib.AdbcStatement.close
  File "adbc_driver_manager/_lib.pyx", line 227, in adbc_driver_manager._lib.check_error
adbc_driver_manager.ProgrammingError: INVALID_ARGUMENT: [FlightSQL] stolen session: 1283150246607583965 (InvalidArgument; ClosePreparedStatement)
Exception ignored in: <function Cursor.__del__ at 0x7fa517960280>
Traceback (most recent call last):
  File "/home/avogelsgesang/.local/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 766, in __del__
  File "/home/avogelsgesang/.local/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 611, in close
  File "adbc_driver_manager/_lib.pyx", line 1077, in adbc_driver_manager._lib.AdbcStatement.close
  File "adbc_driver_manager/_lib.pyx", line 293, in adbc_driver_manager._lib._AdbcHandle._close_child
  File "adbc_driver_manager/_lib.pyx", line 295, in adbc_driver_manager._lib._AdbcHandle._close_child
RuntimeError: Underflow in closing this AdbcStatement
Dominant language
C++
Stars
116
Forks
10
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/arrow-flight-sql-postgresql

All issues in apache/arrow-flight-sql-postgresql

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.