Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ repos:
^airflow-ctl.*\.py$|
^airflow-core/src/airflow/models/.*\.py$|
^airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py$|
^airflow-core/tests/unit/cli/commands/test_dag_command\.py$|
^task_sdk.*\.py$
pass_filenames: true
- id: update-supported-versions
Expand Down
14 changes: 8 additions & 6 deletions airflow-core/tests/unit/cli/commands/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pendulum
import pytest
import time_machine
from sqlalchemy import select
from sqlalchemy import func, select

from airflow import settings
from airflow._shared.timezones import timezone
Expand Down Expand Up @@ -512,7 +512,7 @@ def test_trigger_dag(self):
),
)
with create_session() as session:
dagrun = session.query(DagRun).filter(DagRun.run_id == "test_trigger_dag").one()
dagrun = session.execute(select(DagRun).where(DagRun.run_id == "test_trigger_dag")).scalar_one()

assert dagrun, "DagRun not created"
assert dagrun.run_type == DagRunType.MANUAL
Expand Down Expand Up @@ -540,7 +540,9 @@ def test_trigger_dag_with_microseconds(self):
)

with create_session() as session:
dagrun = session.query(DagRun).filter(DagRun.run_id == "test_trigger_dag_with_micro").one()
dagrun = session.execute(
select(DagRun).where(DagRun.run_id == "test_trigger_dag_with_micro")
).scalar_one()

assert dagrun, "DagRun not created"
assert dagrun.run_type == DagRunType.MANUAL
Expand Down Expand Up @@ -593,7 +595,7 @@ def test_delete_dag(self):
session.add(DM(dag_id=key, bundle_name="dags-folder"))
session.commit()
dag_command.dag_delete(self.parser.parse_args(["dags", "delete", key, "--yes"]))
assert session.query(DM).filter_by(dag_id=key).count() == 0
assert session.execute(select(func.count()).select_from(DM).where(DM.dag_id == key)).scalar_one() == 0
with pytest.raises(AirflowException):
dag_command.dag_delete(
self.parser.parse_args(["dags", "delete", "does_not_exist_dag", "--yes"]),
Expand Down Expand Up @@ -623,7 +625,7 @@ def test_dag_delete_when_backfill_and_dagrun_exist(self):
)
session.commit()
dag_command.dag_delete(self.parser.parse_args(["dags", "delete", key, "--yes"]))
assert session.query(DM).filter_by(dag_id=key).count() == 0
assert session.execute(select(func.count()).select_from(DM).where(DM.dag_id == key)).scalar_one() == 0
with pytest.raises(AirflowException):
dag_command.dag_delete(
self.parser.parse_args(["dags", "delete", "does_not_exist_dag", "--yes"]),
Expand All @@ -639,7 +641,7 @@ def test_delete_dag_existing_file(self, tmp_path):
session.add(DM(dag_id=key, bundle_name="dags-folder", fileloc=os.fspath(path)))
session.commit()
dag_command.dag_delete(self.parser.parse_args(["dags", "delete", key, "--yes"]))
assert session.query(DM).filter_by(dag_id=key).count() == 0
assert session.execute(select(func.count()).select_from(DM).where(DM.dag_id == key)).scalar_one() == 0

def test_cli_list_jobs(self):
args = self.parser.parse_args(["dags", "list-jobs"])
Expand Down