guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2316761972
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,13 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ )
+
Review Comment:
> We have discussed the usage of relationship before at
https://github.com/apache/airflow/pull/54820#pullrequestreview-3144771835. Does
this mean it depends on the model in each case, rather than having all
relationship definitions be the same?
Sorry for not explain the inconsistent.
The key difference is that `DagWarning` has a simple, single-column foreign
key relationship where `DagWarning.dag_id` directly references
`DagModel.dag_id` with the same column name, allowing SQLAlchemy to
automatically infer the join condition.
Log's relationship to TaskInstance is more complex - it needs to join on
`Log.task_id = TaskInstance.task_id`, but SQLAlchemy cannot automatically
determine this relationship because there's no explicit foreign key constraint
and the join logic isn't obvious from the table structure alone.
Thus, I think Log requires explicit `foreign_keys` and `primaryjoin`
parameters to tell SQLAlchemy exactly how to perform the join.
--
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]