diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 939039b0827fb..13672c15465d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -425,6 +425,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/utils/test_log_handlers.py$| ^airflow-core/tests/unit/utils/test_db_cleanup.py$| ^dev/airflow_perf/scheduler_dag_execution_timing.py$| ^providers/openlineage/.*\.py$| diff --git a/airflow-core/tests/unit/utils/test_log_handlers.py b/airflow-core/tests/unit/utils/test_log_handlers.py index 30669ab05997f..8e03cf1980cdc 100644 --- a/airflow-core/tests/unit/utils/test_log_handlers.py +++ b/airflow-core/tests/unit/utils/test_log_handlers.py @@ -36,6 +36,7 @@ from pydantic import TypeAdapter from pydantic.v1.utils import deep_update from requests.adapters import Response +from sqlalchemy import delete, select from airflow import settings from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG @@ -98,8 +99,9 @@ def cleanup_tables(): class TestFileTaskLogHandler: def clean_up(self): with create_session() as session: - session.query(DagRun).delete() - session.query(TaskInstance).delete() + session.execute(delete(DagRun)) + session.execute(delete(TaskInstance)) + session.commit() def setup_method(self): settings.configure_logging() @@ -781,16 +783,14 @@ def test_jinja_id_in_template_for_history( ) TaskInstanceHistory.record_ti(ti, session=session) session.flush() - tih = ( - session.query(TaskInstanceHistory) - .filter_by( - dag_id=ti.dag_id, - task_id=ti.task_id, - run_id=ti.run_id, - map_index=ti.map_index, - try_number=ti.try_number, + tih = session.scalar( + select(TaskInstanceHistory).where( + TaskInstanceHistory.dag_id == ti.dag_id, + TaskInstanceHistory.task_id == ti.task_id, + TaskInstanceHistory.run_id == ti.run_id, + TaskInstanceHistory.map_index == ti.map_index, + TaskInstanceHistory.try_number == ti.try_number, ) - .one() ) fth = FileTaskHandler("") rendered_ti = fth._render_filename(ti, ti.try_number, session=session)