phyk commented on issue #34109:
URL: https://github.com/apache/airflow/issues/34109#issuecomment-2301513862

   This issue is still present. I use airflow 2.9.3, and try to run airflow 
using a sqlite database for the dag.test() command. The database gets created 
correctly using airflow db init/migrate, but when running a dag twice, when 
trying to delete the previous dag run, the error is present again.
   
   raceback (most recent call last):
     File "/airflow/dags/dag.py", line 313, in <module>
       dag.test(
     File "/var/lib/python3.12/site-packages/airflow/utils/session.py", line 
79, in wrapper
       return func(*args, session=session, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/airflow/models/dag.py", line 2890, 
in test
       dr: DagRun = _get_or_create_dagrun(
                    ^^^^^^^^^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/airflow/models/dag.py", line 4205, 
in _get_or_create_dagrun
       session.commit()
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 
1454, in commit
       self._transaction.commit(_to_root=self.future)
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 
832, in commit
       self._prepare_impl()
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 
811, in _prepare_impl
       self.session.flush()
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 
3449, in flush
       self._flush(objects)
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 
3588, in _flush
       with util.safe_reraise():
     File "/var/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", 
line 70, in __exit__
       compat.raise_(
     File "/var/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 
211, in raise_
       raise exception
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 
3549, in _flush
       flush_context.execute()
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", 
line 456, in execute
       rec.execute(self)
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", 
line 667, in execute
       util.preloaded.orm_persistence.delete_obj(
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", 
line 330, in delete_obj
       table_to_mapper = base_mapper._sorted_tables
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", 
line 1184, in __get__
       obj.__dict__[self.__name__] = result = self.fget(obj)
                                              ^^^^^^^^^^^^^^
     File "var/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py", line 
3386, in _sorted_tables
       sorted_ = sql_util.sort_tables(
                 ^^^^^^^^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/sql/ddl.py", line 1217, 
in sort_tables
       for (t, fkcs) in sort_tables_and_constraints(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/sql/ddl.py", line 1289, 
in sort_tables_and_constraints
       filtered = filter_fn(fkc)
                  ^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/sql/ddl.py", line 1207, 
in _skip_fn
       if skip_fn(fk):
          ^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/orm/mapper.py", line 
3369, in skip
       dep = table_to_mapper.get(fk.column.table)
                                 ^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", 
line 1113, in __get__
       obj.__dict__[self.__name__] = result = self.fget(obj)
                                              ^^^^^^^^^^^^^^
     File "/var/lib/python3.12/site-packages/sqlalchemy/sql/schema.py", line 
2532, in column
       return self._resolve_column()
              ^^^^^^^^^^^^^^^^^^^^^^
     File "/var/lib/python3.12/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'
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to