mbarugelCA opened a new issue, #34109: URL: https://github.com/apache/airflow/issues/34109
### Apache Airflow version 2.7.0 ### What happened Calling `airflow tasks test <dag_id> <task_id>` runs the task correctly, but yields the following error after it's done (regardless of failure/success of the task): ``` Traceback (most recent call last): File "/usr/local/bin/airflow", line 8, in <module> sys.exit(main()) File "/usr/local/lib/python3.10/site-packages/airflow/__main__.py", line 60, in main args.func(args) File "/usr/local/lib/python3.10/site-packages/airflow/cli/cli_config.py", line 49, in command return func(*args, **kwargs) File "/usr/local/lib/python3.10/site-packages/airflow/utils/cli.py", line 113, in wrapper return f(*args, **kwargs) File "/usr/local/lib/python3.10/site-packages/airflow/cli/commands/task_command.py", line 633, in task_test with create_session() as session: File "/usr/local/lib/python3.10/contextlib.py", line 142, in __exit__ next(self.gen) File "/usr/local/lib/python3.10/site-packages/airflow/utils/session.py", line 37, in create_session session.commit() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1454, in commit self._transaction.commit(_to_root=self.future) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 832, in commit self._prepare_impl() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 811, in _prepare_impl self.session.flush() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3449, in flush self._flush(objects) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3588, in _flush with util.safe_reraise(): File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__ compat.raise_( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_ raise exception File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush flush_context.execute() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute rec.execute(self) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 667, in execute util.preloaded.orm_persistence.delete_obj( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/persistence.py", line 330, in delete_obj table_to_mapper = base_mapper._sorted_tables File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 1184, in __get__ obj.__dict__[self.__name__] = result = self.fget(obj) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py", line 3386, in _sorted_tables sorted_ = sql_util.sort_tables( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/ddl.py", line 1217, in sort_tables for (t, fkcs) in sort_tables_and_constraints( File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/ddl.py", line 1289, in sort_tables_and_constraints filtered = filter_fn(fkc) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/ddl.py", line 1207, in _skip_fn if skip_fn(fk): File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/mapper.py", line 3369, in skip dep = table_to_mapper.get(fk.column.table) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 1113, in __get__ obj.__dict__[self.__name__] = result = self.fget(obj) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 2532, in column return self._resolve_column() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 2543, in _resolve_column raise exc.NoReferencedTableError( sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'dag_run_note.user_id' could not find table 'ab_user' with which to generate a foreign key to target column 'id' ``` ### What you think should happen instead This error should never happen. It wasn't happening with version `2.5.3`, which I was running before. ### How to reproduce Create this DAG file: ``` from datetime import datetime from airflow import DAG from airflow.decorators import task default_args = { "depends_on_past": False, "start_date": datetime(2022, 3, 9, 0, 0), } with DAG( dag_id="my_dag", default_args=default_args, catchup=False, schedule=None, max_active_runs=1, ) as dag: @task def my_task(): print("Done") my_task() ``` Then run `airflow tasks test my_dag my_task` ### Operating System Debian GNU/Linux 10 (buster) ### Versions of Apache Airflow Providers ``` apache-airflow-providers-amazon==8.5.1 apache-airflow-providers-celery==3.3.2 apache-airflow-providers-common-sql==1.7.0 apache-airflow-providers-ftp==3.5.0 apache-airflow-providers-google==10.6.0 apache-airflow-providers-http==4.5.0 apache-airflow-providers-imap==3.3.0 apache-airflow-providers-jdbc==4.0.1 apache-airflow-providers-mysql==5.2.1 apache-airflow-providers-postgres==5.6.0 apache-airflow-providers-sftp==4.5.0 apache-airflow-providers-slack==7.3.2 apache-airflow-providers-snowflake==4.4.2 apache-airflow-providers-sqlite==3.4.3 apache-airflow-providers-ssh==3.7.1 ``` ### Deployment Docker-Compose ### Deployment details _No response_ ### Anything else This error always happens if you run `airflow tasks test my_dag my_task` If you pass an execution date, it will yield the error the first time, but then it won't error out again: ``` airflow tasks test my_dag my_task 2023-09-01 # error airflow tasks test my_dag my_task 2023-09-01 # second time: no error airflow tasks test my_dag my_task 2023-09-01 # 3rd time: no error airflow tasks test my_dag my_task 2023-09-02 # changed datetime: error ``` I've seen this error both with Postgres and sqlite as backend. ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org