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.

GitOrigin-RevId: dd73a0bffa6c4de93a2dd8dc4460b64aedc51255
  • Loading branch information
potiuk authored and Cloud Composer Team committed Nov 8, 2024
1 parent ff2ec3f commit 7df0c77
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion airflow/providers/elasticsearch/log/es_task_handler.py
Original file line number Diff line number Diff line change
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 7df0c77

Please sign in to comment.