diff --git a/airflow/models/connection.py b/airflow/models/connection.py index 5b10e1b18430f..37a0865014cca 100644 --- a/airflow/models/connection.py +++ b/airflow/models/connection.py @@ -247,7 +247,13 @@ def _create_host(protocol, host) -> str | None: return host def get_uri(self) -> str: - """Return connection in URI format.""" + """ + Return the connection URI in Airflow format. + + The Airflow URI format examples: https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html#uri-format-example + + 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` + """ if self.conn_type and "_" in self.conn_type: self.log.warning( "Connection schemes (type: %s) shall not contain '_' according to RFC3986.", diff --git a/docs/apache-airflow/howto/connection.rst b/docs/apache-airflow/howto/connection.rst index f90f7e96b10e5..d0cc058a4305b 100644 --- a/docs/apache-airflow/howto/connection.rst +++ b/docs/apache-airflow/howto/connection.rst @@ -419,6 +419,10 @@ convenience method :py:meth:`~airflow.models.connection.Connection.get_uri`. It >>> print(f"AIRFLOW_CONN_{c.conn_id.upper()}='{c.get_uri()}'") AIRFLOW_CONN_SOME_CONN='mysql://myname:mypassword@myhost.com?this_param=some+val&that_param=other+val%2A' +.. note:: + + 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. + Additionally, if you have created a connection, you can use ``airflow connections get`` command. .. code-block:: console