Skip to content

Commit 3eeb253

Browse files
committed
Fix execution API server URL handling for relative paths (#49782)
Follow-up of #49747 which broke some workflows including `breeze start-airflow`, requiring #49753. When base_url is a relative path (starts with '/'), default to using http://localhost:8080 as the base URL. This maintains backward compatibility with the previous default behavior while still allowing custom absolute URLs through either `base_url` or `execution_api_server_url` configuration. Fixes `httpx.UnsupportedProtocol` error (as seen in #49753) that occurred when base_url was a relative path without protocol. (cherry picked from commit 3b9ae48)
1 parent fe5d891 commit 3eeb253

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

airflow-core/src/airflow/config_templates/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ core:
537537
execution_api_server_url:
538538
description: |
539539
The url of the execution api server. Default is ``{BASE_URL}/execution/``
540-
where ``{BASE_URL}`` is the base url of the API Server.
540+
where ``{BASE_URL}`` is the base url of the API Server. If ``{BASE_URL}`` is not set,
541+
it will use ``http://localhost:8080`` as the default base url.
541542
version_added: 3.0.0
542543
type: string
543544
example: ~

airflow-core/src/airflow/executors/local_executor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def _execute_work(log: logging.Logger, workload: workloads.ExecuteTask) -> None:
110110
setproctitle(f"airflow worker -- LocalExecutor: {workload.ti.id}")
111111

112112
base_url = conf.get("api", "base_url", fallback="/")
113+
# If it's a relative URL, use localhost:8080 as the default
114+
if base_url.startswith("/"):
115+
base_url = f"http://localhost:8080{base_url}"
113116
default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
114117

115118
# This will return the exit code of the task process, but we don't care about that, just if the

airflow-core/tests/unit/executors/test_local_executor.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,17 @@ def test_clean_stop_on_signal(self):
185185
},
186186
"http://custom-server/execution/",
187187
),
188+
({}, "http://localhost:8080/execution/"),
189+
({("api", "base_url"): "/"}, "http://localhost:8080/execution/"),
190+
({("api", "base_url"): "/airflow/"}, "http://localhost:8080/airflow/execution/"),
191+
],
192+
ids=[
193+
"base_url_fallback",
194+
"custom_server",
195+
"no_base_url_no_custom",
196+
"base_url_no_custom",
197+
"relative_base_url",
188198
],
189-
ids=["base_url_fallback", "custom_server"],
190199
)
191200
@mock.patch("airflow.sdk.execution_time.supervisor.supervise")
192201
def test_execution_api_server_url_config(self, mock_supervise, conf_values, expected_server):

providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def execute_workload(input: str) -> None:
159159
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
160160

161161
base_url = conf.get("api", "base_url", fallback="/")
162+
# If it's a relative URL, use localhost:8080 as the default
163+
if base_url.startswith("/"):
164+
base_url = f"http://localhost:8080{base_url}"
162165
default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
163166

164167
supervise(

providers/edge3/src/airflow/providers/edge3/cli/edge_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ def _run_job_via_supervisor(
272272

273273
try:
274274
base_url = conf.get("api", "base_url", fallback="/")
275+
# If it's a relative URL, use localhost:8080 as the default
276+
if base_url.startswith("/"):
277+
base_url = f"http://localhost:8080{base_url}"
275278
default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
276279

277280
supervise(

0 commit comments

Comments
 (0)