-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Add GetDag endpoint to execution_api #56955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gopidesupavan
merged 12 commits into
apache:main
from
gopidesupavan:dag-state-api-for-task-sdk
Mar 18, 2026
+519
−3
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b46409
Add GetDagState endpoint to execution_api
gopidesupavan b1cb126
Fixup tests
gopidesupavan d7c31c7
Fixup tests
gopidesupavan a1a7c43
Fix static checks
gopidesupavan e664220
Fixup tests
gopidesupavan 9a6f828
Fixup tests
gopidesupavan b6fe52c
Fixup return type
gopidesupavan 3483ff6
Fixup tests and mypy
gopidesupavan 2992934
Add cadwyn migration
gopidesupavan 30393db
Add tests
gopidesupavan f494557
Resolve comments round1
gopidesupavan 6c2a3cf
Replace DAG state endpoint with DAG details endpoint
gopidesupavan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
airflow-core/src/airflow/api_fastapi/execution_api/datamodels/dags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from airflow.api_fastapi.core_api.base import BaseModel | ||
|
|
||
|
|
||
| class DagResponse(BaseModel): | ||
| """Schema for DAG response.""" | ||
|
|
||
| dag_id: str | ||
| is_paused: bool | ||
| bundle_name: str | None | ||
| bundle_version: str | None | ||
| relative_fileloc: str | None | ||
| owners: str | None | ||
| tags: list[str] | ||
| next_dagrun: datetime | None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
airflow-core/src/airflow/api_fastapi/execution_api/routes/dags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from fastapi import APIRouter, HTTPException, status | ||
|
|
||
| from airflow.api_fastapi.common.db.common import SessionDep | ||
| from airflow.api_fastapi.execution_api.datamodels.dags import DagResponse | ||
| from airflow.models.dag import DagModel | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get( | ||
| "/{dag_id}", | ||
| responses={ | ||
| status.HTTP_404_NOT_FOUND: {"description": "DAG not found for the given dag_id"}, | ||
| }, | ||
| ) | ||
| def get_dag( | ||
| dag_id: str, | ||
| session: SessionDep, | ||
| ) -> DagResponse: | ||
| """Get a DAG.""" | ||
| dag_model: DagModel | None = session.get(DagModel, dag_id) | ||
| if not dag_model: | ||
| raise HTTPException( | ||
| status.HTTP_404_NOT_FOUND, | ||
| detail={ | ||
| "reason": "not_found", | ||
| "message": f"The Dag with dag_id: `{dag_id}` was not found", | ||
| }, | ||
| ) | ||
|
|
||
| return DagResponse( | ||
| dag_id=dag_model.dag_id, | ||
| is_paused=dag_model.is_paused, | ||
| bundle_name=dag_model.bundle_name, | ||
| bundle_version=dag_model.bundle_version, | ||
| relative_fileloc=dag_model.relative_fileloc, | ||
| owners=dag_model.owners, | ||
| tags=sorted(tag.name for tag in dag_model.tags), | ||
| next_dagrun=dag_model.next_dagrun, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_04_13.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from cadwyn import VersionChange, endpoint | ||
|
|
||
|
|
||
| class AddDagEndpoint(VersionChange): | ||
| """Add the `/dags/{dag_id}` endpoint.""" | ||
|
|
||
| description = __doc__ | ||
|
|
||
| instructions_to_migrate_to_previous_version = (endpoint("/dags/{dag_id}", ["GET"]).didnt_exist,) |
128 changes: 128 additions & 0 deletions
128
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_dags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime, timezone | ||
| from unittest.mock import ANY | ||
|
|
||
| import pytest | ||
| from sqlalchemy import update | ||
|
|
||
| from airflow.models import DagModel | ||
| from airflow.providers.standard.operators.empty import EmptyOperator | ||
|
|
||
| from tests_common.test_utils.db import clear_db_runs | ||
|
|
||
| pytestmark = pytest.mark.db_test | ||
|
|
||
|
|
||
| class TestDag: | ||
| def setup_method(self): | ||
| clear_db_runs() | ||
|
|
||
| def teardown_method(self): | ||
| clear_db_runs() | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ("state", "expected"), | ||
| [ | ||
| pytest.param(True, True), | ||
| pytest.param(False, False), | ||
| ], | ||
| ) | ||
| def test_get_dag(self, client, session, dag_maker, state, expected): | ||
| """Test getting a DAG.""" | ||
|
|
||
| dag_id = "test_get_dag" | ||
| next_dagrun = datetime(2026, 4, 13, tzinfo=timezone.utc) | ||
|
|
||
| with dag_maker(dag_id=dag_id, session=session, serialized=True, tags=["z_tag", "a_tag"]): | ||
| EmptyOperator(task_id="test_task") | ||
|
|
||
| session.execute( | ||
| update(DagModel) | ||
| .where(DagModel.dag_id == dag_id) | ||
| .values( | ||
| is_paused=state, | ||
| bundle_version="bundle-version", | ||
| relative_fileloc="dags/example.py", | ||
| owners="owner_1", | ||
| next_dagrun=next_dagrun, | ||
| ) | ||
| ) | ||
|
|
||
| session.commit() | ||
|
|
||
| response = client.get( | ||
| f"/execution/dags/{dag_id}", | ||
| ) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == { | ||
| "dag_id": dag_id, | ||
| "is_paused": expected, | ||
| "bundle_name": "dag_maker", | ||
| "bundle_version": "bundle-version", | ||
| "relative_fileloc": "dags/example.py", | ||
| "owners": "owner_1", | ||
| "tags": ["a_tag", "z_tag"], | ||
| "next_dagrun": "2026-04-13T00:00:00Z", | ||
| } | ||
|
|
||
| def test_dag_not_found(self, client, session, dag_maker): | ||
| """Test Dag not found""" | ||
|
|
||
| dag_id = "test_get_dag" | ||
|
|
||
| response = client.get( | ||
| f"/execution/dags/{dag_id}", | ||
| ) | ||
|
|
||
| assert response.status_code == 404 | ||
| assert response.json() == { | ||
| "detail": { | ||
| "message": "The Dag with dag_id: `test_get_dag` was not found", | ||
| "reason": "not_found", | ||
| } | ||
| } | ||
|
|
||
| def test_get_dag_defaults(self, client, session, dag_maker): | ||
| """Test getting a DAG with default model values.""" | ||
|
|
||
| dag_id = "test_get_dag_defaults" | ||
|
|
||
| with dag_maker(dag_id=dag_id, session=session, serialized=True): | ||
| EmptyOperator(task_id="test_task") | ||
|
|
||
| session.commit() | ||
|
|
||
| response = client.get( | ||
| f"/execution/dags/{dag_id}", | ||
| ) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == { | ||
| "dag_id": dag_id, | ||
| "is_paused": False, | ||
| "bundle_name": "dag_maker", | ||
| "bundle_version": None, | ||
| "relative_fileloc": "test_dags.py", | ||
| "owners": "airflow", | ||
| "tags": [], | ||
| "next_dagrun": ANY, | ||
| } |
34 changes: 34 additions & 0 deletions
34
airflow-core/tests/unit/api_fastapi/execution_api/versions/v2026_03_31/test_dags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| pytestmark = pytest.mark.db_test | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def old_ver_client(client): | ||
| client.headers["Airflow-API-Version"] = "2026-03-31" | ||
| return client | ||
|
|
||
|
|
||
| def test_dag_endpoint_not_available_in_previous_version(old_ver_client): | ||
| response = old_ver_client.get("/execution/dags/test_dag") | ||
|
|
||
| assert response.status_code == 404 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.