This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new adea2d714 feat(python/adbc_driver_manager): allow
``connect(profile="foo")`` (#4078)
adea2d714 is described below
commit adea2d714d1d44d57fe2522dc4cda6c18282be2d
Author: David Li <[email protected]>
AuthorDate: Fri Mar 13 09:51:59 2026 +0900
feat(python/adbc_driver_manager): allow ``connect(profile="foo")`` (#4078)
Closes #4077.
---
.../adbc_driver_manager/adbc_driver_manager/dbapi.py | 18 ++++++++++++++++--
python/adbc_driver_manager/pyproject.toml | 1 +
python/adbc_driver_manager/tests/test_dbapi.py | 12 +++++++++++-
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
b/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
index 3590c0d1f..99cbecb20 100644
--- a/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
+++ b/python/adbc_driver_manager/adbc_driver_manager/dbapi.py
@@ -183,9 +183,10 @@ else:
def connect(
- driver: Union[str, pathlib.Path],
+ driver: Optional[Union[str, pathlib.Path]] = None,
uri: Optional[str] = None,
*,
+ profile: Optional[str] = None,
entrypoint: Optional[str] = None,
db_kwargs: Optional[Dict[str, Union[str, pathlib.Path]]] = None,
conn_kwargs: Optional[Dict[str, str]] = None,
@@ -217,10 +218,17 @@ def connect(
where the scheme happens to be the same as the driver name (so
PostgreSQL works, but not SQLite, for example, as SQLite uses
``file:`` URIs).
+
+ - If the URI begins with ``profile://``, then a connection profile
+ will be loaded instead. See :doc:`/format/connection_profiles`.
uri
The "uri" parameter to the database (if applicable). This is
equivalent to passing it in ``db_kwargs`` but is slightly cleaner.
If given, takes precedence over any value in ``db_kwargs``.
+ profile
+ A connection profile to load. Loading ``profile="profile-name"`` is
+ the same as loading the URI ``profile://profile-name``. See
+ :doc:`/format/connection_profiles`.
entrypoint
The driver-specific entrypoint, if different than the default.
db_kwargs
@@ -238,16 +246,22 @@ def connect(
conn = None
db_kwargs = dict(db_kwargs or {})
- db_kwargs["driver"] = driver
+ if driver:
+ db_kwargs["driver"] = driver
if uri:
db_kwargs["uri"] = uri
if entrypoint:
db_kwargs["entrypoint"] = entrypoint
+ if profile:
+ db_kwargs["profile"] = profile
if conn_kwargs is None:
conn_kwargs = {}
# N.B. treating uri = "postgresql://..." as driver = "postgresql", uri =
# "..." is handled at the C driver manager layer
+ if all(k not in db_kwargs for k in ("driver", "uri", "profile")):
+ raise TypeError("Must specify at least one of 'driver', 'uri', or
'profile'")
+
try:
db = _lib.AdbcDatabase(**db_kwargs)
conn = _lib.AdbcConnection(db, **conn_kwargs)
diff --git a/python/adbc_driver_manager/pyproject.toml
b/python/adbc_driver_manager/pyproject.toml
index 32a9d42b4..bad5ad046 100644
--- a/python/adbc_driver_manager/pyproject.toml
+++ b/python/adbc_driver_manager/pyproject.toml
@@ -42,6 +42,7 @@ build-backend = "setuptools.build_meta"
enable = ["cpython-freethreading"]
[tool.pytest.ini_options]
+filterwarnings = ["error"]
markers = [
"duckdb: tests that require DuckDB",
"panicdummy: tests that require the testing-only panicdummy driver",
diff --git a/python/adbc_driver_manager/tests/test_dbapi.py
b/python/adbc_driver_manager/tests/test_dbapi.py
index e94112aed..78506c3df 100644
--- a/python/adbc_driver_manager/tests/test_dbapi.py
+++ b/python/adbc_driver_manager/tests/test_dbapi.py
@@ -735,7 +735,7 @@ def test_connect(tmp_path: pathlib.Path, monkeypatch) ->
None:
cur.execute("SELECT * FROM foo")
assert cur.fetchone() == (1,)
- monkeypatch.setenv("ADBC_DRIVER_PATH", tmp_path)
+ monkeypatch.setenv("ADBC_DRIVER_PATH", str(tmp_path))
with (tmp_path / "foobar.toml").open("w") as f:
f.write(
"""
@@ -747,3 +747,13 @@ shared = "adbc_driver_foobar"
with pytest.raises(dbapi.ProgrammingError, match="NOT_FOUND"):
with dbapi.connect("foobar://localhost:5439"):
pass
+
+ # https://github.com/apache/arrow-adbc/issues/4077: allow profile argument
+ # Just check that the profile gets detected and loaded (should fail)
+ with pytest.raises(dbapi.ProgrammingError, match="NOT_FOUND.*Profile not
found"):
+ with dbapi.connect(profile="nonexistent"):
+ pass
+
+ with pytest.raises(TypeError):
+ with dbapi.connect():
+ pass