This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-5-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 52c2fa8824dbb90abb871775f0f7cd36a97eb59e Author: Jarek Potiuk <[email protected]> AuthorDate: Wed Nov 30 11:47:05 2022 +0100 Fix failing test case for db clean in newer sqlalchemy (#28004) Fixing of ambiguity of treating "*" in SQLAlchemy 4.1.42 made our tests to fail, because they were trying to execute the query from aliased table as a standalone queryi for verificaiton, where in "reality" the same query would be executed as part of "CREATE AS" statement. The tests started to fail with the new SQLAlchemy and the fix was to change our tests to also run "CREATE AS" statement and count number of rows in the created temporary table. (cherry picked from commit 122d60b5b4547f7380d58eea148552607264122e) --- tests/utils/test_db_cleanup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/utils/test_db_cleanup.py b/tests/utils/test_db_cleanup.py index 422bec37f3..c505408a3b 100644 --- a/tests/utils/test_db_cleanup.py +++ b/tests/utils/test_db_cleanup.py @@ -30,7 +30,7 @@ from sqlalchemy.ext.declarative import DeclarativeMeta from airflow.models import DagModel, DagRun, TaskInstance from airflow.operators.python import PythonOperator -from airflow.utils.db_cleanup import _build_query, _cleanup_table, config_dict, run_cleanup +from airflow.utils.db_cleanup import CreateTableAs, _build_query, _cleanup_table, config_dict, run_cleanup from airflow.utils.session import create_session from tests.test_utils.db import clear_db_dags, clear_db_datasets, clear_db_runs, drop_tables_with_prefix @@ -172,6 +172,7 @@ class TestDBCleanup: num_tis=10, external_trigger=external_trigger, ) + target_table_name = "_airflow_temp_table_name" with create_session() as session: clean_before_date = base_date.add(**date_add_kwargs) query = _build_query( @@ -179,7 +180,11 @@ class TestDBCleanup: clean_before_timestamp=clean_before_date, session=session, ) - assert len(query.all()) == expected_to_delete + stmt = CreateTableAs(target_table_name, query.selectable) + session.execute(stmt) + res = session.execute(f"SELECT COUNT(1) FROM {target_table_name}") + for row in res: + assert row[0] == expected_to_delete @pytest.mark.parametrize( "table_name, date_add_kwargs, expected_to_delete, external_trigger",
