Skip to content

Commit

Permalink
Fix urlparse schemaless-behaviour on Python 3.9+ (#33289)
Browse files Browse the repository at this point in the history
The urlparse stdlib call behaves differently on Python 3.9+ for
schemaless-URLs. It parses string hostname into a schema instead
of netloc. The issue is still open and discussed

* psf/requests#6455

and apparently it will not be solved, so we need to workaround it
if we still want to support legacy, schemaless URLs to be accepted
by Elasticsearch handler.
  • Loading branch information
potiuk committed Aug 10, 2023
1 parent c14cb85 commit dd73a0b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion airflow/providers/elasticsearch/log/es_task_handler.py
Expand Up @@ -143,7 +143,9 @@ def format_url(host: str) -> str:
parsed_url = urlparse(host)

# Check if the scheme is either http or https
if not parsed_url.scheme:
# Handles also the Python 3.9+ case where urlparse understands "localhost:9200"
# differently than urlparse in Python 3.8 and below (https://github.com/psf/requests/issues/6455)
if parsed_url.scheme not in ("http", "https"):
host = "http://" + host
parsed_url = urlparse(host)

Expand Down

0 comments on commit dd73a0b

Please sign in to comment.