Skip to content

Commit

Permalink
Add FastAPI migration done marker (apache#42198)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrejeambrun authored Sep 16, 2024
1 parent f3b238a commit e55b181
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions airflow/api_connexion/endpoints/dag_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from airflow.exceptions import AirflowException, DagNotFound
from airflow.models.dag import DagModel, DagTag
from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.api_migration import mark_fastapi_migration_done
from airflow.utils.db import get_query_count
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.www.decorators import action_logging
Expand Down Expand Up @@ -89,6 +90,7 @@ def get_dag_details(
return dag_detail_schema.dump(dag_model)


@mark_fastapi_migration_done
@security.requires_access_dag("GET")
@format_parameters({"limit": check_limit})
@provide_session
Expand Down
40 changes: 40 additions & 0 deletions airflow/utils/api_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# 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.
"""
Utilities for migration legacy endpoints to FastAPI.
This module can be deleted once the AIP-84 is completed and the legacy API is deleted.
"""

from __future__ import annotations

from typing import Callable, TypeVar

from airflow.typing_compat import ParamSpec

PS = ParamSpec("PS")
RT = TypeVar("RT")


def mark_fastapi_migration_done(function: Callable[PS, RT]) -> Callable[PS, RT]:
"""
Mark an endpoint as migrated over to the new FastAPI API.
This will help track what endpoints need to be migrated and the one that can be safely deleted.
"""
return function
2 changes: 2 additions & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
from airflow.timetables.simple import ContinuousTimetable
from airflow.utils import json as utils_json, timezone, usage_data_collection, yaml
from airflow.utils.airflow_flask_app import get_airflow_app
from airflow.utils.api_migration import mark_fastapi_migration_done
from airflow.utils.dag_edges import dag_edges
from airflow.utils.db import get_query_count
from airflow.utils.docs import get_doc_url_for_provider, get_docs_url
Expand Down Expand Up @@ -3409,6 +3410,7 @@ def historical_metrics_data(self):
@expose("/object/next_run_datasets/<string:dag_id>")
@auth.has_access_dag("GET", DagAccessEntity.RUN)
@auth.has_access_dataset("GET")
@mark_fastapi_migration_done
def next_run_datasets(self, dag_id):
"""Return datasets necessary, and their status, for the next dag run."""
dag = get_airflow_app().dag_bag.get_dag(dag_id)
Expand Down
4 changes: 4 additions & 0 deletions contributing-docs/17_adding_api_endpoints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ For example, in v1.yaml, you might add:
Including schemas helps in automatically generating API documentation and ensures consistent data structures across the API.

After adding or modifying schemas, make sure to run the pre-commit hooks again to update any generated files.

Note on the New FastAPI API
---------------------------
As part of the AIP-84 you may be adding new endpoints to the FastAPI API by migrating some legacy endpoints. In case you are doing so don't forget to mark the legacy endpoint (Flask one) with the ``@mark_fastapi_migration_done`` decorator. This will help maintainers keep track of the endpoints remaining for the migration and those already migrated.

0 comments on commit e55b181

Please sign in to comment.