This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit f22584854e11c527f20bec4967cb7e61dfa5a134
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Thu Sep 18 19:05:33 2025 +0100

    Fix _get_serdag query in grid ui (#55771)
    
    If version is None, we should return None instead of looking for
    the dag version attached to the version. currently this raises attribute
    error that Nonetype has no attribute serialized dag.
    
    Also, I added a joinedload of serdag to the version query to get everything
    at the first query instead of another query at version.serialized_dag
    
    (cherry picked from commit b0b2621e8bf2a9ef1922cbd4b74160c2115bf254)
---
 .../src/airflow/api_fastapi/core_api/routes/ui/grid.py         | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py 
b/airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py
index 7ff49ac27c1..fea5abc52e0 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py
@@ -23,6 +23,7 @@ from typing import TYPE_CHECKING, Annotated
 import structlog
 from fastapi import Depends, HTTPException, status
 from sqlalchemy import select
+from sqlalchemy.orm import joinedload
 
 from airflow.api_fastapi.auth.managers.models.resource_details import 
DagAccessEntity
 from airflow.api_fastapi.common.db.common import SessionDep, paginated_select
@@ -81,16 +82,23 @@ def _get_latest_serdag(dag_id, session):
 
 def _get_serdag(dag_id, dag_version_id, session) -> SerializedDagModel | None:
     # this is a simplification - we account for structure based on the first 
task
-    version = session.scalar(select(DagVersion).where(DagVersion.id == 
dag_version_id))
+    version = session.scalar(
+        select(DagVersion)
+        .where(DagVersion.id == dag_version_id)
+        .options(joinedload(DagVersion.serialized_dag))
+    )
     if not version:
         version = session.scalar(
             select(DagVersion)
             .where(
                 DagVersion.dag_id == dag_id,
             )
+            .options(joinedload(DagVersion.serialized_dag))
             .order_by(DagVersion.id)  # ascending cus this is mostly for 
pre-3.0 upgrade
             .limit(1)
         )
+    if not version:
+        return None
     if not (serdag := version.serialized_dag):
         log.error(
             "No serialized dag found",

Reply via email to