Skip to content

Commit

Permalink
[AIRFLOW-5260] Allow empty uri arguments in connection strings (#5855)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7fb729d)
  • Loading branch information
sb2nov authored and potiuk committed Aug 20, 2019
1 parent 74fbd16 commit 7738f6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def parse_from_uri(self, uri):
if uri_parts.password else uri_parts.password
self.port = uri_parts.port
if uri_parts.query:
self.extra = json.dumps(dict(parse_qsl(uri_parts.query)))
self.extra = json.dumps(dict(parse_qsl(uri_parts.query, keep_blank_values=True)))

def get_password(self):
if self._password and self.is_encrypted:
Expand Down
13 changes: 13 additions & 0 deletions tests/models/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def test_connection_from_uri_with_extras(self):
self.assertDictEqual(connection.extra_dejson, {'extra1': 'a value',
'extra2': '/path/'})

def test_connection_from_uri_with_empty_extras(self):
uri = 'scheme://user:password@host%2flocation:1234/schema?' \
'extra1=a%20value&extra2='
connection = Connection(uri=uri)
self.assertEqual(connection.conn_type, 'scheme')
self.assertEqual(connection.host, 'host/location')
self.assertEqual(connection.schema, 'schema')
self.assertEqual(connection.login, 'user')
self.assertEqual(connection.password, 'password')
self.assertEqual(connection.port, 1234)
self.assertDictEqual(connection.extra_dejson, {'extra1': 'a value',
'extra2': ''})

def test_connection_from_uri_with_colon_in_hostname(self):
uri = 'scheme://user:password@host%2flocation%3ax%3ay:1234/schema?' \
'extra1=a%20value&extra2=%2fpath%2f'
Expand Down

0 comments on commit 7738f6a

Please sign in to comment.