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

   I believe I have a fix as well as a workaround. Create the following as the 
plugin file, `plugins/workaround_dag_run_note_init.py`:
   
   ```py
   """
   Workaround for: https://github.com/apache/airflow/issues/34109
   
   DagRunNote has a foreign key `user_id` (and thus a dependency) to User, but 
it
   seems `airflow.models.dagrun` gets loaded first (at least when running 
`airflow
   tasks test DAG_ID TASK_ID`). Loading User first seems to solve the issue.
   """
   
   from airflow.auth.managers.fab.models import User
   from airflow.models.dagrun import DagRunNote
   ```
   
   The equivalent fix would be to encode the dependency into the foreign key 
definition, establishing proper import ordering.
   
   ```py
   from airflow.auth.managers.fab.models import User
   
   class DagRunNote(Base):
       user_id = Column(
           Integer,
           ForeignKey(User.id, name="dag_run_note_user_fkey"),  # reference 
User.id instead of using "ab_user.id"
           nullable=True,
       )
   ```
   
   I can create a PR. I'm not familiar with sqlalchemy though, scrutiny is 
welcome


-- 
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