arrow-adbc: RuntimeError: Cannot close AdbcConnection with open AdbcStatement

I am using polars library to write to Azure Postgre SQL DB.

This is my code:
import polars as pl
from datetime import datetime
data = {
    'text': ['foo', 'bar', 'baz'],
    'bool': [True, False, True],
    'datetime': [datetime.now(), datetime.now(), datetime.now()],
    'date': ['2022-03-24', '2022-03-23', '2022-03-22'],
    'float': [1.1, 2.2, 3.3]
}
df = pl.DataFrame(data, schema={
    'text': pl.Utf8,
    'bool': pl.Boolean,
    'datetime': pl.Datetime('us', None),
    'date': pl.Date,
    'float': pl.Float64
})
connection_string = f"postgresql://{servername}:5432/{dbname}?user={username}&password={pw}"
df.write_database(
            table_name="schema_name.my_table",
            connection_uri=connection_string,
            if_exists='append',
            engine='adbc'
        )
This is the error:
    df.write_database(
  File "/home/mv/.virtualenvs/env_fsspec/lib/python3.10/site-packages/polars/dataframe/frame.py", line 2940, in write_database
    with _open_adbc_connection(connection_uri) as conn:
  File "/home/mv/.virtualenvs/env_fsspec/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 217, in __exit__
    self.close()
  File "/home/mv/.virtualenvs/env_fsspec/lib/python3.10/site-packages/adbc_driver_manager/dbapi.py", line 302, in close
    self._conn.close()
  File "adbc_driver_manager/_lib.pyx", line 851, in adbc_driver_manager._lib.AdbcConnection.close
  File "adbc_driver_manager/_lib.pyx", line 452, in adbc_driver_manager._lib._AdbcHandle._check_open_children
  File "adbc_driver_manager/_lib.pyx", line 454, in adbc_driver_manager._lib._AdbcHandle._check_open_children
RuntimeError: Cannot close AdbcConnection with open AdbcStatement
Versions I have installed:
adbc-driver-manager==0.3.0
adbc-driver-postgresql==0.3.0
pandas==1.5.3
polars==0.16.14
pyarrow==11.0.0

Please let me know if you need anything further.

Many thanks!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 24 (13 by maintainers)

Most upvoted comments

I filed #855 and and #856 for some minor improvements here

We can leave this issue open too, I’ll use this to also add integration tests with Polars (I hadn’t realized they had done this - so thank you for bringing it up to me) and see if I can reproduce things/improve things on our side and Polars side (context manager, and supporting the “fail” mode they list)