Skip to content

Commit

Permalink
Fix urlparse schemaless-behaviour on Python 3.9+ (apache#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 authored and ferruzzi committed Aug 17, 2023
1 parent 913795a commit ddb09a2
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 ddb09a2

Please sign in to comment.