You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ferruzzi (via GitHub)" <gi...@apache.org> on 2026/04/15 01:59:32 UTC
[PR] clean up redundant api server uri generation [airflow]
ferruzzi opened a new pull request, #65277:
URL: https://github.com/apache/airflow/pull/65277
A fast-follow for @kaxil/ https://github.com/apache/airflow/pull/62645 had three spots using the same redundant code, this PR just moves them into a shared helper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3088117648
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -250,11 +250,17 @@ def _execute_workload_pre_3_2(input: str) -> None:
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
- base_url = conf.get("api", "base_url", fallback="/")
- # If it's a relative URL, use localhost:8080 as the default.
- if base_url.startswith("/"):
- base_url = f"http://localhost:8080{base_url}"
- default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ # TODO: Remove the inline resolution once the celery provider's minimum airflow version is >= 3.2.1
+ if AIRFLOW_V_3_2_PLUS:
+ from airflow.executors.base_executor import get_execution_api_server_url
+
+ server = get_execution_api_server_url()
+ else:
+ base_url = conf.get("api", "base_url", fallback="/")
+ if base_url.startswith("/"):
+ base_url = f"http://localhost:8080{base_url}"
+ default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ server = conf.get("core", "execution_api_server_url", fallback=default_execution_api_server)
Review Comment:
`_execute_workload_pre_3_2()` is only called when `not AIRFLOW_V_3_2_PLUS` (see `execute_workload()`), so the `if AIRFLOW_V_3_2_PLUS:` branch here is effectively dead code and the TODO about 3.2.1 is misleading. Please remove the unreachable branch and keep just the pre-3.2 inline resolution (or, if this helper is intended for some other call path, adjust the dispatch condition accordingly).
```suggestion
base_url = conf.get("api", "base_url", fallback="/")
if base_url.startswith("/"):
base_url = f"http://localhost:8080{base_url}"
default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
server = conf.get("core", "execution_api_server_url", fallback=default_execution_api_server)
```
##########
airflow-core/src/airflow/executors/base_executor.py:
##########
@@ -43,6 +43,25 @@
PARALLELISM: int = conf.getint("core", "PARALLELISM")
+
+def get_execution_api_server_url(conf_source: AirflowConfigParser | ExecutorConf = conf) -> str:
+ """
+ Resolve the execution API server URL from configuration.
+
+ :param conf_source: Configuration source to read from. Defaults to the global ``conf``.
+ Team-specific executors can pass their own config (e.g. ``ExecutorConf``) to resolve
+ a team-specific URL.
+ """
+ base_url = conf_source.get("api", "base_url", fallback="/")
+
+ # Both .get() statements have a fallback= which guarantee a str, mypy sees
+ # .get()'s return is typed as str | None so we have to add redundant checks
+ if not base_url or base_url.startswith("/"):
+ base_url = f"http://localhost:8080{base_url}"
+ default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ return conf_source.get("core", "execution_api_server_url", fallback=default_execution_api_server) # type: ignore[return-value]
Review Comment:
This helper uses `# type: ignore[return-value]` even though both calls pass `fallback=` values that are `str`. Instead of suppressing type checking here, consider tightening the typing (e.g., overload `ExecutorConf.get` to mirror `AirflowConfigParser.get` when `fallback` is provided, or use a local `cast(str, ...)`) so the function can return `str` without an ignore.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3089782047
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -250,11 +250,17 @@ def _execute_workload_pre_3_2(input: str) -> None:
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
- base_url = conf.get("api", "base_url", fallback="/")
- # If it's a relative URL, use localhost:8080 as the default.
- if base_url.startswith("/"):
- base_url = f"http://localhost:8080{base_url}"
- default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ # TODO: Remove the inline resolution once the celery provider's minimum airflow version is >= 3.2.1
+ if AIRFLOW_V_3_2_PLUS:
Review Comment:
I promised this as a fast-follow to @kaxil - Kaxil, do you think this is alright in 3.3 or should I try to backport it or 3.2.1? I agree with Vincent here (3.3) but making sure you are alright with it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3087118451
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -250,11 +250,17 @@ def _execute_workload_pre_3_2(input: str) -> None:
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
- base_url = conf.get("api", "base_url", fallback="/")
- # If it's a relative URL, use localhost:8080 as the default.
- if base_url.startswith("/"):
- base_url = f"http://localhost:8080{base_url}"
- default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ # TODO: Remove the inline resolution once the celery provider's minimum airflow version is >= 3.2.1
+ if AIRFLOW_V_3_2_PLUS:
Review Comment:
The comment and the code does not match. Code says `>= 3.2.0`, comment says `>= 3.2.1`. Plus, do you intend to backport the core airflow piece of this PR in `v3-2-test`? It does not look like a bug fix. If not, then it should be `AIRFLOW_V_3_3_PLUS`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3089782047
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -250,11 +250,17 @@ def _execute_workload_pre_3_2(input: str) -> None:
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
- base_url = conf.get("api", "base_url", fallback="/")
- # If it's a relative URL, use localhost:8080 as the default.
- if base_url.startswith("/"):
- base_url = f"http://localhost:8080{base_url}"
- default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ # TODO: Remove the inline resolution once the celery provider's minimum airflow version is >= 3.2.1
+ if AIRFLOW_V_3_2_PLUS:
Review Comment:
I promised this as a fast-follow to @kaxil - Kaxil, do you think this is alright waiting for 3.3 or should I try to backport it to 3.2.1? I agree with Vincent here (3.3 seems fine) but making sure you are alright with it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3088299579
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -250,11 +250,17 @@ def _execute_workload_pre_3_2(input: str) -> None:
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
- base_url = conf.get("api", "base_url", fallback="/")
- # If it's a relative URL, use localhost:8080 as the default.
- if base_url.startswith("/"):
- base_url = f"http://localhost:8080{base_url}"
- default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ # TODO: Remove the inline resolution once the celery provider's minimum airflow version is >= 3.2.1
+ if AIRFLOW_V_3_2_PLUS:
Review Comment:
This branch is unreachable. `_execute_workload_pre_3_2` is only called when `not AIRFLOW_V_3_2_PLUS` (line 207 of `execute_workload`), so `AIRFLOW_V_3_2_PLUS` is always `False` inside this function. The import and call to `get_execution_api_server_url()` will never execute.
The TODO and guard can be dropped -- just keep the inline resolution as-is. When the celery provider's minimum airflow version is bumped to >= 3.2, the entire `_execute_workload_pre_3_2` function goes away (along with this code).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi merged PR #65277:
URL: https://github.com/apache/airflow/pull/65277
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3089811131
##########
airflow-core/src/airflow/executors/base_executor.py:
##########
@@ -43,6 +43,25 @@
PARALLELISM: int = conf.getint("core", "PARALLELISM")
+
+def get_execution_api_server_url(conf_source: AirflowConfigParser | ExecutorConf = conf) -> str:
+ """
+ Resolve the execution API server URL from configuration.
+
+ :param conf_source: Configuration source to read from. Defaults to the global ``conf``.
+ Team-specific executors can pass their own config (e.g. ``ExecutorConf``) to resolve
+ a team-specific URL.
+ """
+ base_url = conf_source.get("api", "base_url", fallback="/")
+
+ # Both .get() statements have a fallback= which guarantee a str, mypy sees
+ # .get()'s return is typed as str | None so we have to add redundant checks
+ if not base_url or base_url.startswith("/"):
+ base_url = f"http://localhost:8080{base_url}"
+ default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ return conf_source.get("core", "execution_api_server_url", fallback=default_execution_api_server) # type: ignore[return-value]
Review Comment:
I had considered cast() but not sure that's really any better. get() returns `str | None` so even with a fallback, which makes it impossible to return None, mypy still gets grumpy. Hence the ignore. Is `cast` any better in the end?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] clean up redundant api server uri generation [airflow]
Posted by "ferruzzi (via GitHub)" <gi...@apache.org>.
ferruzzi commented on code in PR #65277:
URL: https://github.com/apache/airflow/pull/65277#discussion_r3089800312
##########
providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py:
##########
@@ -250,11 +250,17 @@ def _execute_workload_pre_3_2(input: str) -> None:
log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
- base_url = conf.get("api", "base_url", fallback="/")
- # If it's a relative URL, use localhost:8080 as the default.
- if base_url.startswith("/"):
- base_url = f"http://localhost:8080{base_url}"
- default_execution_api_server = f"{base_url.rstrip('/')}/execution/"
+ # TODO: Remove the inline resolution once the celery provider's minimum airflow version is >= 3.2.1
+ if AIRFLOW_V_3_2_PLUS:
Review Comment:
> When the celery provider's minimum airflow version is bumped to >= 3.2, the entire _execute_workload_pre_3_2 function goes away (along with this code).
Yeah, I was trying to make it really obvious that this was the plan rather than counting on Future Us to remember when that version bump happens. I overdid it though, you're right.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org