pierrejeambrun commented on code in PR #46279:
URL: https://github.com/apache/airflow/pull/46279#discussion_r1935837044


##########
tests/api_fastapi/core_api/routes/ui/test_structure.py:
##########
@@ -407,7 +472,45 @@ def test_should_return_200(self, test_client, params, 
expected):
         assert response.status_code == 200
         assert not DeepDiff(response.json(), expected, ignore_order=True)
 
+    @pytest.mark.parametrize(
+        "params, expected",
+        [
+            pytest.param(
+                {"dag_id": DAG_ID},
+                LATEST_VERSION_DAG_RESPONSE,
+                id="get_default_version",
+            ),
+            pytest.param(
+                {"dag_id": DAG_ID, "dag_version": 1},
+                FIRST_VERSION_DAG_RESPONSE,
+                id="get_oldest_version",
+            ),
+            pytest.param(
+                {"dag_id": DAG_ID, "dag_version": 2},
+                SECOND_VERSION_DAG_RESPONSE,
+                id="get_specific_version",
+            ),
+            pytest.param(
+                {"dag_id": DAG_ID, "dag_version": 3},
+                LATEST_VERSION_DAG_RESPONSE,
+                id="get_latest_version",
+            ),
+        ],
+    )
+    @pytest.mark.usefixtures("make_dag_with_multiple_version")
+    def test_should_return_200_with_multiple_versions(self, test_client, 
params, expected):
+        response = test_client.get("/ui/structure/structure_data", 
params=params)
+        assert response.status_code == 200
+        assert not DeepDiff(response.json(), expected, ignore_order=True)

Review Comment:
   Maybe don't use `DeepDiff` we use it nowhere else. Maybe a simple 
`response.json() == expected` is enough ?



##########
airflow/api_fastapi/core_api/routes/ui/structure.py:
##########
@@ -43,9 +45,23 @@ def structure_data(
     include_downstream: QueryIncludeDownstream = False,
     root: str | None = None,
     external_dependencies: bool = False,
+    dag_version: int | None = None,
 ) -> StructureDataResponse:
     """Get Structure Data."""
-    dag = request.app.state.dag_bag.get_dag(dag_id)
+    if dag_version is None:
+        dag = request.app.state.dag_bag.get_dag(dag_id)
+    else:
+        serialized_dag: SerializedDagModel = session.scalar(
+            select(SerializedDagModel)
+            .join(DagVersion)
+            .where(SerializedDagModel.dag_id == dag_id, 
DagVersion.version_number == dag_version)
+        )
+        if serialized_dag is None:
+            raise HTTPException(
+                status.HTTP_404_NOT_FOUND,
+                f"Dag with id {dag_id} with version {dag_version} was not 
found",

Review Comment:
   Nit:
   ```suggestion
                   f"Dag with id {dag_id} and version {dag_version} was not 
found",
   ```



##########
airflow/api_fastapi/core_api/routes/ui/structure.py:
##########
@@ -43,9 +45,23 @@ def structure_data(
     include_downstream: QueryIncludeDownstream = False,
     root: str | None = None,
     external_dependencies: bool = False,
+    dag_version: int | None = None,
 ) -> StructureDataResponse:
     """Get Structure Data."""
-    dag = request.app.state.dag_bag.get_dag(dag_id)
+    if dag_version is None:
+        dag = request.app.state.dag_bag.get_dag(dag_id)
+    else:
+        serialized_dag: SerializedDagModel = session.scalar(
+            select(SerializedDagModel)
+            .join(DagVersion)
+            .where(SerializedDagModel.dag_id == dag_id, 
DagVersion.version_number == dag_version)

Review Comment:
   Nit: Maybe we can find a way to always read from db and not from the dagbdag.
   
   If find it awkward to read from DagBag in some cases and from the DB in some 
other cases. (maybe order be version number decreasing and take the first one ? 
🤔 



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