This is an automated email from the ASF dual-hosted git repository. jedcunningham pushed a commit to branch v2-9-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit df37d60d498d9bfac073bb1aa59ca6734a7fe6db Author: Andrey Anshin <[email protected]> AuthorDate: Thu Apr 11 23:18:26 2024 +0400 Fix `SAWarning` 'Coercing Subquery object into a select() for use in IN()' (#38926) (cherry picked from commit 05ba268d05787bfbec6b1f5eefde2c90c64bf6b5) --- airflow/api_connexion/endpoints/import_error_endpoint.py | 8 +++----- airflow/utils/db_cleanup.py | 4 +--- airflow/www/views.py | 5 +---- pyproject.toml | 1 + 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/airflow/api_connexion/endpoints/import_error_endpoint.py b/airflow/api_connexion/endpoints/import_error_endpoint.py index a56cb97c41..274d842d18 100644 --- a/airflow/api_connexion/endpoints/import_error_endpoint.py +++ b/airflow/api_connexion/endpoints/import_error_endpoint.py @@ -94,11 +94,9 @@ def get_import_errors( if not can_read_all_dags: # if the user doesn't have access to all DAGs, only display errors from visible DAGs readable_dag_ids = security.get_readable_dags() - dagfiles_subq = ( - select(DagModel.fileloc).distinct().where(DagModel.dag_id.in_(readable_dag_ids)).subquery() - ) - query = query.where(ImportErrorModel.filename.in_(dagfiles_subq)) - count_query = count_query.where(ImportErrorModel.filename.in_(dagfiles_subq)) + dagfiles_stmt = select(DagModel.fileloc).distinct().where(DagModel.dag_id.in_(readable_dag_ids)) + query = query.where(ImportErrorModel.filename.in_(dagfiles_stmt)) + count_query = count_query.where(ImportErrorModel.filename.in_(dagfiles_stmt)) total_entries = session.scalars(count_query).one() import_errors = session.scalars(query.offset(offset).limit(limit)).all() diff --git a/airflow/utils/db_cleanup.py b/airflow/utils/db_cleanup.py index e119c4228b..4475209b77 100644 --- a/airflow/utils/db_cleanup.py +++ b/airflow/utils/db_cleanup.py @@ -186,9 +186,7 @@ def _do_delete(*, query, orm_model, skip_archive, session): if dialect_name == "sqlite": pk_cols = source_table.primary_key.columns delete = source_table.delete().where( - tuple_(*pk_cols).in_( - select(*[target_table.c[x.name] for x in source_table.primary_key.columns]).subquery() - ) + tuple_(*pk_cols).in_(select(*[target_table.c[x.name] for x in source_table.primary_key.columns])) ) else: delete = source_table.delete().where( diff --git a/airflow/www/views.py b/airflow/www/views.py index 8a5ea38270..55aa5a5e50 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -952,10 +952,7 @@ class Airflow(AirflowBaseView): # if the user doesn't have access to all DAGs, only display errors from visible DAGs import_errors = import_errors.where( errors.ImportError.filename.in_( - select(DagModel.fileloc) - .distinct() - .where(DagModel.dag_id.in_(filter_dag_ids)) - .subquery() + select(DagModel.fileloc).distinct().where(DagModel.dag_id.in_(filter_dag_ids)) ) ) diff --git a/pyproject.toml b/pyproject.toml index 82e3cbc528..1448a01dac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -480,6 +480,7 @@ filterwarnings = [ "error::pytest.PytestCollectionWarning", # Avoid building cartesian product which might impact performance "error:SELECT statement has a cartesian product between FROM:sqlalchemy.exc.SAWarning:airflow", + 'error:Coercing Subquery object into a select\(\) for use in IN\(\):sqlalchemy.exc.SAWarning:airflow', "ignore::DeprecationWarning:flask_appbuilder.filemanager", "ignore::DeprecationWarning:flask_appbuilder.widgets", # https://github.com/dpgaspar/Flask-AppBuilder/pull/1940
