Coverage for /home/airflow/.local/lib/python3.12/site-packages/airflow/api_fastapi/core_api/routes/ui/calendar.py: 83%
18 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 14:22 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 14:22 +0000
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17from __future__ import annotations
19from typing import Annotated, Literal
21from fastapi import Depends
23from airflow.api_fastapi.auth.managers.models.resource_details import DagAccessEntity
24from airflow.api_fastapi.common.dagbag import DagBagDep, get_latest_version_of_dag
25from airflow.api_fastapi.common.db.common import SessionDep
26from airflow.api_fastapi.common.parameters import RangeFilter, datetime_range_filter_factory
27from airflow.api_fastapi.common.router import AirflowRouter
28from airflow.api_fastapi.core_api.datamodels.ui.calendar import CalendarTimeRangeCollectionResponse
29from airflow.api_fastapi.core_api.security import requires_access_dag
30from airflow.api_fastapi.core_api.services.ui.calendar import CalendarService
31from airflow.models.dagrun import DagRun
33calendar_router = AirflowRouter(prefix="/calendar", tags=["Calendar"])
36@calendar_router.get(
37 "/{dag_id}",
38 dependencies=[
39 Depends(
40 requires_access_dag(
41 method="GET",
42 access_entity=DagAccessEntity.TASK_INSTANCE,
43 )
44 ),
45 Depends(
46 requires_access_dag(
47 method="GET",
48 access_entity=DagAccessEntity.RUN,
49 )
50 ),
51 ],
52)
53def get_calendar(
54 dag_id: str,
55 session: SessionDep,
56 dag_bag: DagBagDep,
57 logical_date: Annotated[RangeFilter, Depends(datetime_range_filter_factory("logical_date", DagRun))],
58 partition_date: Annotated[RangeFilter, Depends(datetime_range_filter_factory("partition_date", DagRun))],
59 granularity: Literal["hourly", "daily"] = "daily",
60) -> CalendarTimeRangeCollectionResponse:
61 """Get calendar data for a Dag including historical and planned Dag runs."""
62 dag = get_latest_version_of_dag(dag_bag, dag_id, session)
64 calendar_service = CalendarService()
66 return calendar_service.get_calendar_data(
67 dag_id=dag_id,
68 session=session,
69 dag=dag,
70 logical_date=logical_date,
71 partition_date=partition_date,
72 granularity=granularity,
73 )