Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"