Skip to content

fix(provider): honour driver_name when a connection string omits the DBAPI - #33

Open
test-codeop wants to merge 2 commits into
fix-workflowfrom
uncover-agent-2511630941
Open

test-codeop wants to merge 2 commits into
fix-workflowfrom
uncover-agent-2511630941

Conversation

@test-codeop

Copy link
Copy Markdown
Collaborator

Summary

A provider configured with a bare connection string:

data: postgresql://postgres:secret@localhost/test

resolves to SQLAlchemy's default DBAPI for the backend — psycopg (v3) for PostgreSQL. Deployments that only install psycopg2 (per requirements-provider.txt) then fail at engine creation:

sqlalchemy/dialects/postgresql/psycopg.py in import_dbapi
ModuleNotFoundError: No module named 'psycopg'

even though PostgreSQLProvider.__init__ pins driver_name='postgresql+psycopg2'. The pin is silently ignored whenever data is a string, because store_db_parameters routes it to self.db_conn and get_engine uses the URL verbatim.

The CI failure in tests/provider/test_postgresql_provider (and test_api_connection_rfc3986 in the manager suite, which also builds its connection string with a bare postgresql:// URL) is exactly this.

Fix

In get_engine, when the caller's URL has no +driver suffix and the provider's driver_name does, rewrite the URL's drivername to the pinned one. Explicitly-pinned URLs (postgresql+psycopg://...) are untouched.

Test plan

  • Verified with mocked create_engine:
    • postgresql://… + pin postgresql+psycopg2 → engine URL becomes postgresql+psycopg2
    • postgresql+psycopg://… → untouched
    • no conn_str → built from driver_name as before
  • test_api_connection_rfc3986 now reaches the real connection attempt (psycopg2.OperationalError: connection refused locally) instead of failing at import psycopg, confirming the v2 driver is selected.

Fixes geopython#2424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI is failing, because 'psycopg' is not installed

1 participant