This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new 2d8799f6f46 [v3-4-test] Fix dag.test() failing for task ids with
non-ASCII characters (#74472) (#77767)
2d8799f6f46 is described below
commit 2d8799f6f46c3803c31386a85b2774bba771cf92
Author: Rahul Vats <[email protected]>
AuthorDate: Mon Nov 30 16:14:29 2026 +0530
[v3-4-test] Fix dag.test() failing for task ids with non-ASCII characters
(#74472) (#77767)
* Fix dag.test() failing for task ids with non-ASCII characters
A task id like "Købsmoms" passes task id validation, but dag.test() failed
as
soon as such a task pushed an XCom. In-process execution sends requests
through httpx.WSGITransport, which puts the decoded URL path into PATH_INFO
as a plain str. a2wsgi follows PEP 3333 and expects UTF-8 bytes decoded as
latin-1, so any non-ASCII character in the path raised UnicodeDecodeError or
UnicodeEncodeError and the task failed. Requests over a real HTTP connection
are not affected.
* Use httpx2 in the non-ASCII in-process transport tests
The in-process Execution API transport now uses httpx2, and test_app.py
no longer imports httpx after main was merged in.
* Refer to httpx2 in the in-process path middleware docstring
The in-process transport moved from httpx to httpx2.
---------
(cherry picked from commit f97e74a252790f571923bf4cb38ef727ea0cb949)
Co-authored-by: Per Andersen <[email protected]>
Co-authored-by: Claude <[email protected]>
---
.../api_fastapi/execution_api/in_process.py | 18 +++++++++++-
.../unit/api_fastapi/execution_api/test_app.py | 33 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/in_process.py
b/airflow-core/src/airflow/api_fastapi/execution_api/in_process.py
index eb428196d43..9f4713c8cff 100644
--- a/airflow-core/src/airflow/api_fastapi/execution_api/in_process.py
+++ b/airflow-core/src/airflow/api_fastapi/execution_api/in_process.py
@@ -131,7 +131,23 @@ class InProcessExecutionAPI:
thread = threading.Thread(target=loop.run_forever,
name="InProcessExecutionAPI-loop", daemon=True)
thread.start()
- middleware = ASGIMiddleware(self.app, loop=loop)
+ class PEP3333PathMiddleware(ASGIMiddleware):
+ """
+ Pass ``PATH_INFO`` and ``SCRIPT_NAME`` on to a2wsgi in PEP 3333
form.
+
+ ``httpx2.WSGITransport`` puts the percent-decoded URL path into
the environ as a regular ``str``,
+ whereas PEP 3333 (and ``a2wsgi``, which follows it) expects UTF-8
bytes decoded as latin-1.
+ Without this, any non-ASCII character in the path, such as a
non-ASCII ``task_id``, fails with a
+ ``UnicodeDecodeError`` or ``UnicodeEncodeError``.
+ """
+
+ def __call__(self, environ, start_response):
+ for key in ("PATH_INFO", "SCRIPT_NAME"):
+ if key in environ:
+ environ[key] =
environ[key].encode("utf-8").decode("latin-1")
+ return super().__call__(environ, start_response)
+
+ middleware = PEP3333PathMiddleware(self.app, loop=loop)
# https://github.com/abersheeran/a2wsgi/discussions/64
async def start_lifespan(cm: AsyncExitStack, app: FastAPI):
diff --git a/airflow-core/tests/unit/api_fastapi/execution_api/test_app.py
b/airflow-core/tests/unit/api_fastapi/execution_api/test_app.py
index 7049fc2a60f..f0e42063ce7 100644
--- a/airflow-core/tests/unit/api_fastapi/execution_api/test_app.py
+++ b/airflow-core/tests/unit/api_fastapi/execution_api/test_app.py
@@ -265,6 +265,39 @@ def test_in_process_execution_api_transport_lifecycle():
assert not thread.is_alive()
[email protected]("task_id", ["Købsmoms", "タスク"])
+def test_in_process_execution_api_handles_non_ascii_path(task_id):
+ """Non-ASCII path segments (e.g. a non-ASCII task_id) must reach the app
intact."""
+ app = FastAPI()
+
+ @app.get("/echo/{task_id}")
+ async def echo(task_id: str):
+ return task_id
+
+ api = InProcessExecutionAPI(app)
+ with httpx2.Client(transport=api.transport) as client:
+ response = client.get(f"http://localhost/echo/{task_id}")
+ assert response.status_code == 200
+ assert response.json() == task_id
+
+
[email protected]("script_name", ["/Købsmoms", "/タスク"])
+def test_in_process_execution_api_handles_non_ascii_script_name(script_name):
+ """A non-ASCII ``SCRIPT_NAME`` must reach the app intact as the ASGI
``root_path``."""
+ app = FastAPI()
+
+ @app.get("/echo")
+ async def echo(request: Request):
+ return request.scope["root_path"]
+
+ api = InProcessExecutionAPI(app)
+ transport = httpx2.WSGITransport(app=api.transport.app,
script_name=script_name)
+ with httpx2.Client(transport=transport) as client:
+ response = client.get("http://localhost/echo")
+ assert response.status_code == 200
+ assert response.json() == script_name
+
+
@pytest.fixture
def in_process_db_app():
engine = settings.async_engine