Skip to content

Can't connect to ADBC Driver if importlib.util is not implicitly loaded #134

@henryharbeck

Description

@henryharbeck

What happens?

I wanted to to try DuckDB's newly packaged ADBC driver, but had issues connecting to it consistently.

I found this to be due to Python's and other libraries' behaviour of sometimes implicitly loading the importlib.util submodule and other times not. It should be explicitly imported in the DuckDB source.

To Reproduce

echo 'from adbc_driver_duckdb.dbapi import connect; connect()' | uv run --no-project --isolated --with duckdb --with adbc-driver-manager -
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from adbc_driver_duckdb.dbapi import connect; connect()
                                                  ~~~~~~~^^
  File "/home/henry/.cache/uv/archive-v0/JVG3pd2AYTdo8Is7icbUy/lib/python3.13/site-packages/adbc_driver_duckdb/dbapi.py", line 100, in connect
    db = adbc_driver_duckdb.connect(path)
  File "/home/henry/.cache/uv/archive-v0/JVG3pd2AYTdo8Is7icbUy/lib/python3.13/site-packages/adbc_driver_duckdb/__init__.py", line 38, in connect
    return adbc_driver_manager.AdbcDatabase(driver=driver_path(), entrypoint="duckdb_adbc_init")
                                                   ~~~~~~~~~~~^^
  File "/home/henry/.cache/uv/archive-v0/JVG3pd2AYTdo8Is7icbUy/lib/python3.13/site-packages/adbc_driver_duckdb/__init__.py", line 45, in driver_path
    duckdb_module_spec = importlib.util.find_spec("_duckdb")
                         ^^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'util'

Whereas when PyArrow is installed, this seems to implicitly load importlib.util

echo 'from adbc_driver_duckdb.dbapi import connect; connect()' | uv run --no-project --isolated --with duckdb --with adbc-driver-manager --with pyarrow -
# Found duckdb shared library at /home/henry/.cache/uv/archive-v0/ZRiulh9VPSJkuNkvzZdaa/lib/python3.13/site-packages/_duckdb.cpython-313-x86_64-linux-gnu.so

Going deeper

Also it is inconsistent in the REPR between Python versions

# 3.13 works in the REPR, but not outside it (-q for quiet)
$ uv run --python 3.13 python -q
>>> import importlib; importlib.util
<module 'importlib.util' (frozen)>

$ echo 'import importlib; importlib.util' | uv run --python 3.13 -
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import importlib; importlib.util
                      ^^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'util'

# 3.11 work in neither
$ uv run --python 3.11 python -q
>>> import importlib; importlib.util
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'util'

$ echo 'import importlib; importlib.util' | uv run --python 3.11 -
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'util'

OS:

Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.31

DuckDB Package Version:

1.4.1

Python Version:

3.13.2

Full Name:

Henry Harbeck

Affiliation:

None

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions