You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ds...@apache.org on 2022/12/30 08:29:30 UTC

[airflow] branch main updated: Allow generation of connection URI to work when no conn type (#26765)

This is an automated email from the ASF dual-hosted git repository.

dstandish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b124d6cac1 Allow generation of connection URI to work when no conn type (#26765)
b124d6cac1 is described below

commit b124d6cac1180e21d21408f74729e77f75a46cb9
Author: Daniel Standish <15...@users.noreply.github.com>
AuthorDate: Fri Dec 30 00:29:19 2022 -0800

    Allow generation of connection URI to work when no conn type (#26765)
    
    Previously if get_uri was called it would fail with `NoneType not iterable`, because of the check `if '-' in conn_type`.
---
 airflow/models/connection.py    | 7 +++++--
 tests/always/test_connection.py | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/airflow/models/connection.py b/airflow/models/connection.py
index da67410a39..5f7406d9d4 100644
--- a/airflow/models/connection.py
+++ b/airflow/models/connection.py
@@ -206,13 +206,16 @@ class Connection(Base, LoggingMixin):
 
     def get_uri(self) -> str:
         """Return connection in URI format"""
-        if "_" in self.conn_type:
+        if self.conn_type and "_" in self.conn_type:
             self.log.warning(
                 "Connection schemes (type: %s) shall not contain '_' according to RFC3986.",
                 self.conn_type,
             )
 
-        uri = f"{str(self.conn_type).lower().replace('_', '-')}://"
+        if self.conn_type:
+            uri = f"{self.conn_type.lower().replace('_', '-')}://"
+        else:
+            uri = "//"
 
         authority_block = ""
         if self.login is not None:
diff --git a/tests/always/test_connection.py b/tests/always/test_connection.py
index dac7bb1104..750b36ef53 100644
--- a/tests/always/test_connection.py
+++ b/tests/always/test_connection.py
@@ -735,3 +735,11 @@ class TestConnection(unittest.TestCase):
     def test_extra_warnings_non_dict_json(self):
         with pytest.warns(DeprecationWarning, match="not parse as a dictionary"):
             Connection(conn_id="test_extra", conn_type="none", extra='"hi"')
+
+    def test_get_uri_no_conn_type(self):
+        # no conn type --> scheme-relative URI
+        assert Connection().get_uri() == "//"
+        # with host, still works
+        assert Connection(host="abc").get_uri() == "//abc"
+        # parsing back as conn still works
+        assert Connection(uri="//abc").host == "abc"