-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Deprecate some functions in the experimental API #19931
Changes from all commits
6ab9972
b2cd44a
f1b5685
00599d9
b90bd82
55798a0
89b0056
4d8ea49
afed421
d111ffa
89b2a17
1ffd06c
0cda3ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# | ||
# 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. | ||
"""Delete DAGs APIs.""" | ||
import logging | ||
|
||
from sqlalchemy import or_ | ||
|
||
from airflow import models | ||
from airflow.exceptions import AirflowException, DagNotFound | ||
from airflow.models import DagModel, TaskFail | ||
from airflow.models.serialized_dag import SerializedDagModel | ||
from airflow.utils.db import get_sqla_model_classes | ||
from airflow.utils.session import provide_session | ||
from airflow.utils.state import State | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@provide_session | ||
def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int: | ||
""" | ||
:param dag_id: the dag_id of the DAG to delete | ||
:param keep_records_in_log: whether keep records of the given dag_id | ||
in the Log table in the backend database (for reasons like auditing). | ||
The default value is True. | ||
:param session: session used | ||
:return count of deleted dags | ||
""" | ||
log.info("Deleting DAG: %s", dag_id) | ||
running_tis = ( | ||
session.query(models.TaskInstance.state) | ||
.filter(models.TaskInstance.dag_id == dag_id) | ||
.filter(models.TaskInstance.state == State.RUNNING) | ||
.first() | ||
) | ||
if running_tis: | ||
raise AirflowException("TaskInstances still running") | ||
dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first() | ||
if dag is None: | ||
raise DagNotFound(f"Dag id {dag_id} not found") | ||
|
||
# Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval. | ||
# There may be a lag, so explicitly removes serialized DAG here. | ||
if SerializedDagModel.has_dag(dag_id=dag_id, session=session): | ||
SerializedDagModel.remove_dag(dag_id=dag_id, session=session) | ||
|
||
count = 0 | ||
|
||
for model in get_sqla_model_classes(): | ||
if hasattr(model, "dag_id"): | ||
if keep_records_in_log and model.__name__ == 'Log': | ||
continue | ||
cond = or_(model.dag_id == dag_id, model.dag_id.like(dag_id + ".%")) | ||
count += session.query(model).filter(cond).delete(synchronize_session='fetch') | ||
if dag.is_subdag: | ||
parent_dag_id, task_id = dag_id.rsplit(".", 1) | ||
for model in TaskFail, models.TaskInstance: | ||
count += ( | ||
session.query(model).filter(model.dag_id == parent_dag_id, model.task_id == task_id).delete() | ||
) | ||
|
||
# Delete entries in Import Errors table for a deleted DAG | ||
# This handles the case when the dag_id is changed in the file | ||
session.query(models.ImportError).filter(models.ImportError.filename == dag.fileloc).delete( | ||
synchronize_session='fetch' | ||
) | ||
|
||
return count |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,9 +19,12 @@ | |||||||||||
from datetime import datetime | ||||||||||||
from typing import Dict | ||||||||||||
|
||||||||||||
from deprecated import deprecated | ||||||||||||
|
||||||||||||
from airflow.api.common.experimental import check_and_get_dag, check_and_get_dagrun | ||||||||||||
|
||||||||||||
|
||||||||||||
@deprecated(reason="Use DagRun().get_state() instead", version="2.2.3") | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still used in airflow/www/api/experimental/endpoints.py -- if we are deprecating it we will need to change those references too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The experimental API is also deprecated: See airflow/airflow/www/api/experimental/endpoints.py Lines 56 to 60 in b20e6d3
My thinking is that if someone is using it externally which may be possible, then we should warn |
||||||||||||
def get_dag_run_state(dag_id: str, execution_date: datetime) -> Dict[str, str]: | ||||||||||||
"""Return the Dag Run state identified by the given dag_id and execution_date. | ||||||||||||
|
||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the
get_pool
experimental API raises PoolNotFound when the pool does not exist. Since I have moved it to the Pool model, I don't want it to raise hence raising not found hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at where this function is being called, I wonder if we should just get rid of this exception altogether and just return
Optional
. Not sure about this.