Skip to content

Commit 79733e9

Browse files
Fix #47555: PostgreSQL URI driver issue (#47709)
* Fix #47555: PostgreSQL URI scheme issue * Fix: allow configuring PostgreSQL connection driver Added support for customizing the PostgreSQL connection driver (`postgres` vs `postgresql`) via the `postgres_driver` option in the extra JSON field. * Fix #47555: PostgreSQL URI scheme issue * Fix: allow configuring PostgreSQL connection driver Added support for customizing the PostgreSQL connection driver (`postgres` vs `postgresql`) via the `postgres_driver` option in the extra JSON field. * Add the documentation for the 'designator' parameter in the PostgreSQL extras section * Remove the code that constructs the URI based on connection type * Update get_uri method docstring * Clarify that get_uri() does not return a SQLAlchemy URI * Fix rst-backticks * Remove designer description * Fix format code with ruff --------- Co-authored-by: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com>
1 parent 8242ba5 commit 79733e9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

airflow/models/connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ def _create_host(protocol, host) -> str | None:
247247
return host
248248

249249
def get_uri(self) -> str:
250-
"""Return connection in URI format."""
250+
"""
251+
Return the connection URI in Airflow format.
252+
253+
The Airflow URI format examples: https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html#uri-format-example
254+
255+
Note that the URI returned by this method is **not** SQLAlchemy-compatible, if you need a SQLAlchemy-compatible URI, use the :attr:`~airflow.providers.common.sql.hooks.sql.DbApiHook.sqlalchemy_url`
256+
"""
251257
if self.conn_type and "_" in self.conn_type:
252258
self.log.warning(
253259
"Connection schemes (type: %s) shall not contain '_' according to RFC3986.",

docs/apache-airflow/howto/connection.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ convenience method :py:meth:`~airflow.models.connection.Connection.get_uri`. It
419419
>>> print(f"AIRFLOW_CONN_{c.conn_id.upper()}='{c.get_uri()}'")
420420
AIRFLOW_CONN_SOME_CONN='mysql://myname:mypassword@myhost.com?this_param=some+val&that_param=other+val%2A'
421421
422+
.. note::
423+
424+
The ``get_uri()`` method return the connection URI in Airflow format, **not** a SQLAlchemy-compatible URI. if you need a SQLAlchemy-compatible URI for database connections, use :attr:`~airflow.providers.common.sql.hooks.sql.DbApiHook.sqlalchemy_url` property instead.
425+
422426
Additionally, if you have created a connection, you can use ``airflow connections get`` command.
423427

424428
.. code-block:: console

0 commit comments

Comments
 (0)