Skip to content

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres when adding connection via UI #55223

@Bee2A

Description

@Bee2A

Apache Airflow Provider(s)

postgres

Versions of Apache Airflow Providers

apache-airflow-providers-postgres==6.2.0

Apache Airflow version

2.11.0

Operating System

Debian

Deployment

Docker-Compose

Deployment details

FROM apache/airflow:2.11.0-python3.12

What happened

  1. Adding a new Posgtres-Connection via the UI and chosing "Postgres" as the Connection Type
Image Image
  1. Retrieving the URI for this connection in a Task with: uri =Connection.get_connection_from_secrets('Test-Postgres').get_uri() results in: 'postgres://my_user:my_pw@my_host:5432/my_db'
  2. Using the generated URI ends up in the following exception, because it starts with 'postgres://' and thus is not supported by SQLAlchemy 1.4+
  3. Exception:
    File "", line 2, in create_engine
    File "/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
    return fn(*args, **kwargs)
    ^^^^^^^^^^^^^^^^^^^
    File "/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 518, in create_engine
    entrypoint = u._get_entrypoint()
    ^^^^^^^^^^^^^^^^^^^
    File "/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/engine/url.py", line 662, in _get_entrypoint
    cls = registry.load(name)
    ^^^^^^^^^^^^^^^^^^^
    File "/home/airflow/.local/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 343, in load
    raise exc.NoSuchModuleError(
    sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres

What you think should happen instead

A URI for a Postgres-connection added via the UI should either result in:
'postgresql://my_user:my_pw@my_host:5432/my_db'

or

'postgresql+psycopg2://my_user:my_pw@my_host:5432/my_db'

How to reproduce

Add a Postgres-Connection via UI and use the retrieved uri for a db-connection

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

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