Skip to content

Commit d3d7f8a

Browse files
committed
fix: fix mypy type error in dagrun.py
1 parent e510552 commit d3d7f8a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

airflow-core/src/airflow/models/dagrun.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from sqlalchemy.sql.expression import false, select
5757
from sqlalchemy.sql.functions import coalesce
5858
from sqlalchemy_utils import UUIDType
59+
from sqlalchemy.engine import ScalarResult
5960

6061
from airflow.callbacks.callback_requests import DagCallbackRequest, DagRunContext
6162
from airflow.configuration import conf as airflow_conf
@@ -351,7 +352,7 @@ def __init__(
351352
if queued_at is NOTSET:
352353
self.queued_at = pendulum.now(tz="UTC") if state == DagRunState.QUEUED else None
353354
elif queued_at is not None:
354-
self.queued_at = queued_at
355+
self.queued_at = cast(datetime, queued_at)
355356
if run_type is not None:
356357
self.run_type = run_type
357358
self.creating_job_id = creating_job_id
@@ -572,11 +573,12 @@ def active_runs_of_dags(
572573
)
573574
if exclude_backfill:
574575
query = query.where(cls.run_type != DagRunType.BACKFILL_JOB)
575-
return dict(session.execute(query).all())
576+
result = session.execute(query).all()
577+
return {dag_id:count for dag_id, count in result}
576578

577579
@classmethod
578580
@retry_db_transaction
579-
def get_running_dag_runs_to_examine(cls, session: Session) -> Query:
581+
def get_running_dag_runs_to_examine(cls, session: Session) -> ScalarResult[DagRun]:
580582
"""
581583
Return the next DagRuns that the scheduler should attempt to schedule.
582584
@@ -615,7 +617,7 @@ def get_running_dag_runs_to_examine(cls, session: Session) -> Query:
615617

616618
@classmethod
617619
@retry_db_transaction
618-
def get_queued_dag_runs_to_set_running(cls, session: Session) -> Query:
620+
def get_queued_dag_runs_to_set_running(cls, session: Session) -> ScalarResult[DagRun]:
619621
"""
620622
Return the next queued DagRuns that the scheduler should attempt to schedule.
621623
@@ -732,11 +734,13 @@ def find(
732734
qry = qry.where(cls.dag_id.in_(dag_ids))
733735

734736
if is_container(run_id):
735-
qry = qry.where(cls.run_id.in_(run_id))
737+
run_ids = cast(Iterable[str], run_id)
738+
qry = qry.where(cls.run_id.in_(run_ids))
736739
elif run_id is not None:
737740
qry = qry.where(cls.run_id == run_id)
738741
if is_container(logical_date):
739-
qry = qry.where(cls.logical_date.in_(logical_date))
742+
logical_dates = cast(Iterable[datetime], logical_date)
743+
qry = qry.where(cls.logical_date.in_(logical_dates))
740744
elif logical_date is not None:
741745
qry = qry.where(cls.logical_date == logical_date)
742746
if logical_start_date and logical_end_date:

0 commit comments

Comments
 (0)