ephraimbuddy commented on code in PR #62160:
URL: https://github.com/apache/airflow/pull/62160#discussion_r2832424845
##########
airflow-core/src/airflow/api_fastapi/common/db/dag_runs.py:
##########
@@ -52,3 +52,18 @@ def eager_load_dag_run_for_validation() ->
tuple[LoaderOption, ...]:
.joinedload(DagVersion.bundle),
joinedload(DagRun.dag_run_note),
)
+
+
+def eager_load_dag_run_for_list() -> tuple[LoaderOption, ...]:
+ """
+ Eager loading options for listing DagRuns.
+
+ IMPORTANT: Do NOT load task instances / histories here.
+ Those collections can be huge and will cause extra queries and/or row
explosion,
+ which makes list endpoints slow on large installations.
+ """
+ return (
+ joinedload(DagRun.dag_model),
+ joinedload(DagRun.dag_run_note),
+ joinedload(DagRun.created_dag_version).joinedload(DagVersion.bundle),
Review Comment:
Might be safer to also joinload DagVersion.dag_model instead of relying on
the implicit load
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py:
##########
@@ -81,10 +81,22 @@ class DAGRunResponse(BaseModel):
triggering_user_name: str | None
conf: dict | None
note: str | None
- dag_versions: list[DagVersionResponse]
bundle_version: str | None
dag_display_name: str = Field(validation_alias=AliasPath("dag_model",
"dag_display_name"))
partition_key: str | None
+ # Internal helper field: populated from the ORM relationship
+ # Must be excluded from output, and MUST NOT trigger DagRun.dag_versions
property
+ created_dag_version_obj: DagVersionResponse | None = Field(
+ default=None,
+ validation_alias="created_dag_version",
+ exclude=True,
+ )
+
+ @computed_field(return_type=list[DagVersionResponse])
+ def dag_versions(self) -> list[DagVersionResponse]:
+ # Derive from already-eager-loaded relationship.
+ # Do NOT touch run.dag_versions (ORM property).
+ return [self.created_dag_version_obj] if self.created_dag_version_obj
else []
Review Comment:
This changes dag_version for every endpoint that uses DagRunResponse and not
just DagRun list. This is also a change in behaviour for non-versioned bundles
which previously returned all unique dag versions collected from TIs and TIH.
--
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]