Skip to content

Commit

Permalink
Allow generation of connection URI to work when no conn type (#26765)
Browse files Browse the repository at this point in the history
Previously if get_uri was called it would fail with `NoneType not iterable`, because of the check `if '-' in conn_type`.
  • Loading branch information
dstandish authored Dec 30, 2022
1 parent 2e7b9f5 commit b124d6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions airflow/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,16 @@ def _parse_from_uri(self, uri: str):

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:
Expand Down
8 changes: 8 additions & 0 deletions tests/always/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,11 @@ def test_extra_warnings_non_json(self):
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"

0 comments on commit b124d6c

Please sign in to comment.