You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "pierrejeambrun (via GitHub)" <gi...@apache.org> on 2025/02/27 15:59:53 UTC

[PR] AIP-38 Default value for version selector [airflow]

pierrejeambrun opened a new pull request, #47154:
URL: https://github.com/apache/airflow/pull/47154

   This add some logic to pre-select the appropriate dag version depending on the current url.
   
   If the user explicitly uses the version selector, or there is a `dag_version` param in the URL, nothing happens.
   
   If there is no `dag_version` explicitely specified in the URL, then we pre-select the dag version based on:
   - on a dag -> latest_dag_version 
   ![Screenshot 2025-02-27 at 16 57 02](https://github.com/user-attachments/assets/64c24abf-146f-4a11-872e-69e4e200858b)
   - on a DagRun -> latest dag version of the DagRun
   ![Screenshot 2025-02-27 at 16 57 17](https://github.com/user-attachments/assets/1983f03d-65ed-498a-a7c9-422d38c0bd03)
   - on a TI -> dag version of the TI. Handled the case of the `MappedTaskInstance` summary -> fallsback to the `DagRun` case. 
   ![Screenshot 2025-02-27 at 16 57 46](https://github.com/user-attachments/assets/61deed9f-5c2b-42a0-91e7-9802a5ddf243)
   
   
   Clicking on TIs in the graph without a version explicitely set will dynamically update the graph based on the TI version. If we want to freeze the dag for  a specific version to navigate the graph -> explicitely to so using the version selector.
   
   
   
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1974173080


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,86 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const mapIndexParam = searchParams.get("map_index");
+  const mapIndex = parseInt(mapIndexParam ?? "-1", 10);

Review Comment:
   If you're on main we moved `map_index` from search params to regular params



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1975663023


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,85 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const { dagId = "", mapIndexParam = "-1", runId = "", taskId = "" } = useParams();
+
+  const mapIndex = parseInt(mapIndexParam, 10);
+
+  const { data: dagData } = useDagServiceGetDagDetails(
+    {
+      dagId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) },
+  );
+
+  const { data: runData } = useDagRunServiceGetDagRun(
+    {
+      dagId,
+      dagRunId: runId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) },
+  );
+
+  const { data: taskData } = useTaskServiceGetTask(
+    {
+      dagId,
+      taskId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) && Boolean(taskId) },
+  );
+
+  const { data: mappedTaskInstanceData } = useTaskInstanceServiceGetMappedTaskInstance(
+    {
+      dagId,
+      dagRunId: runId,
+      mapIndex,
+      taskId,
+    },
+    undefined,
+    // Do not enable on a task instance summary. Mapped task but no mapIndex defined.
+    { enabled: taskData !== undefined && !Boolean(mapIndex === -1 && taskData.is_mapped) },

Review Comment:
   ```suggestion
       { enabled: taskData !== undefined && !Boolean(mapIndex === "-1" && taskData.is_mapped) },
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1977239139


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,85 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const { dagId = "", mapIndexParam = "-1", runId = "", taskId = "" } = useParams();

Review Comment:
   Nice catch thanks, I did some last minute adjustment and forgot to test again this part.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1975470418


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,86 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const mapIndexParam = searchParams.get("map_index");
+  const mapIndex = parseInt(mapIndexParam ?? "-1", 10);

Review Comment:
   Updated, thanks



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1975662120


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,85 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const { dagId = "", mapIndexParam = "-1", runId = "", taskId = "" } = useParams();

Review Comment:
   ```suggestion
     const { dagId = "", mapIndex = "-1", runId = "", taskId = "" } = useParams();
   ```
   
   The variable name needs to be an exact match to the param specified in `router.tsx`



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1975662708


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,85 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const { dagId = "", mapIndexParam = "-1", runId = "", taskId = "" } = useParams();
+
+  const mapIndex = parseInt(mapIndexParam, 10);
+
+  const { data: dagData } = useDagServiceGetDagDetails(
+    {
+      dagId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) },
+  );
+
+  const { data: runData } = useDagRunServiceGetDagRun(
+    {
+      dagId,
+      dagRunId: runId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) },
+  );
+
+  const { data: taskData } = useTaskServiceGetTask(
+    {
+      dagId,
+      taskId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) && Boolean(taskId) },
+  );
+
+  const { data: mappedTaskInstanceData } = useTaskInstanceServiceGetMappedTaskInstance(
+    {
+      dagId,
+      dagRunId: runId,
+      mapIndex,

Review Comment:
   ```suggestion
         mapIndex: parseInt(mapIndex, 10)
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #47154:
URL: https://github.com/apache/airflow/pull/47154


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-38 Default value for version selector [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #47154:
URL: https://github.com/apache/airflow/pull/47154#discussion_r1977239506


##########
airflow/ui/src/hooks/useSelectedVersion.ts:
##########
@@ -0,0 +1,85 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useParams, useSearchParams } from "react-router-dom";
+
+import {
+  useDagRunServiceGetDagRun,
+  useDagServiceGetDagDetails,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const useSelectedVersion = (): string | undefined => {
+  const [searchParams] = useSearchParams();
+
+  const selectedVersionUrl = searchParams.get(SearchParamsKeys.VERSION_NUMBER);
+
+  const { dagId = "", mapIndexParam = "-1", runId = "", taskId = "" } = useParams();
+
+  const mapIndex = parseInt(mapIndexParam, 10);
+
+  const { data: dagData } = useDagServiceGetDagDetails(
+    {
+      dagId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) },
+  );
+
+  const { data: runData } = useDagRunServiceGetDagRun(
+    {
+      dagId,
+      dagRunId: runId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) },
+  );
+
+  const { data: taskData } = useTaskServiceGetTask(
+    {
+      dagId,
+      taskId,
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) && Boolean(taskId) },
+  );
+
+  const { data: mappedTaskInstanceData } = useTaskInstanceServiceGetMappedTaskInstance(
+    {
+      dagId,
+      dagRunId: runId,
+      mapIndex,
+      taskId,
+    },
+    undefined,
+    // Do not enable on a task instance summary. Mapped task but no mapIndex defined.
+    { enabled: taskData !== undefined && !Boolean(mapIndex === -1 && taskData.is_mapped) },

Review Comment:
   Done thanks



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org