Skip to content

Commit

Permalink
Fix task sdk client dry-run mode (#46524)
Browse files Browse the repository at this point in the history
* Fix task sdk client dry-run mode

The `run_after` field was missing in the fake dag run response.

* Fix trailing whitespaces
  • Loading branch information
feluelle authored Feb 6, 2025
1 parent 993a009 commit 7af4571
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions task_sdk/src/airflow/sdk/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def noop_handler(request: httpx.Request) -> httpx.Response:
"logical_date": "2021-01-01T00:00:00Z",
"start_date": "2021-01-01T00:00:00Z",
"run_type": DagRunType.MANUAL,
"run_after": "2021-01-01T00:00:00Z",
},
"max_tries": 0,
},
Expand Down
33 changes: 33 additions & 0 deletions task_sdk/tests/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def make_client(transport: httpx.MockTransport) -> Client:
return Client(base_url="test://server", token="", transport=transport)


def make_client_w_dry_run() -> Client:
"""Get a client with dry_run enabled"""
return Client(base_url=None, dry_run=True, token="")


def make_client_w_responses(responses: list[httpx.Response]) -> Client:
"""Helper fixture to create a mock client with custom responses."""

Expand All @@ -49,6 +54,34 @@ def handle_request(request: httpx.Request) -> httpx.Response:


class TestClient:
@pytest.mark.parametrize(
["path", "json_response"],
[
(
"/task-instances/1/run",
{
"dag_run": {
"dag_id": "test_dag",
"run_id": "test_run",
"logical_date": "2021-01-01T00:00:00Z",
"start_date": "2021-01-01T00:00:00Z",
"run_type": "manual",
"run_after": "2021-01-01T00:00:00Z",
},
"max_tries": 0,
},
),
],
)
def test_dry_run(self, path, json_response):
client = make_client_w_dry_run()
assert client.base_url == "dry-run://server"

resp = client.get(path)

assert resp.status_code == 200
assert resp.json() == json_response

def test_error_parsing(self):
responses = [
httpx.Response(422, json={"detail": [{"loc": ["#0"], "msg": "err", "type": "required"}]})
Expand Down

0 comments on commit 7af4571

Please sign in to comment.