Skip to content

Commit 6acc49f

Browse files
committed
fix mypy errors in delete_dag.py
1 parent c47c081 commit 6acc49f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

airflow-core/src/airflow/api/common/delete_dag.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from __future__ import annotations
2121

2222
import logging
23-
from typing import TYPE_CHECKING
23+
from typing import TYPE_CHECKING, cast
2424

2525
from sqlalchemy import delete, select
2626

@@ -34,6 +34,7 @@
3434
from airflow.utils.state import TaskInstanceState
3535

3636
if TYPE_CHECKING:
37+
from sqlalchemy.engine import CursorResult, Result
3738
from sqlalchemy.orm import Session
3839

3940
log = logging.getLogger(__name__)
@@ -70,13 +71,14 @@ def delete_dag(dag_id: str, keep_records_in_log: bool = True, session: Session =
7071
model for model in get_sqla_model_classes() if model.__name__ not in ["TaskInstance", "DagRun"]
7172
]
7273

73-
count = 0
74+
count: int = 0
7475
for model in models_for_deletion:
7576
if hasattr(model, "dag_id") and (not keep_records_in_log or model.__name__ != "Log"):
76-
result = session.execute(
77+
result: Result = session.execute(
7778
delete(model).where(model.dag_id == dag_id).execution_options(synchronize_session="fetch")
7879
)
79-
count += result.rowcount or 0
80+
cursor_result = cast("CursorResult", result)
81+
count += cursor_result.rowcount
8082

8183
# Delete entries in Import Errors table for a deleted DAG
8284
# This handles the case when the dag_id is changed in the file

0 commit comments

Comments
 (0)