You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "bbovenzi (via GitHub)" <gi...@apache.org> on 2025/09/30 20:51:25 UTC

[PR] Check if any tasks have HITL operator before fetching HITL details [airflow]

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

   We were fetching HITL details too often.
   I still feel like this is all too complicated and brittle. So I would love to explore ways to actually know more about a Dag/Run/Task so we only display necessary tabs. Or redesign the view to not need so many tabs.
   
   
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
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] Check if any tasks have HITL operator before fetching HITL details [airflow]

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


##########
airflow-core/src/airflow/ui/src/queries/useHitlDetails.ts:
##########
@@ -0,0 +1,73 @@
+/*!
+ * 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 { useTaskInstanceServiceGetHitlDetails, useTaskServiceGetTasks } from "openapi/queries";
+
+type HITLDetailsParams = {
+  dagId?: string;
+  dagRunId?: string;
+  responseReceived?: boolean;
+  state?: Array<string>;
+  taskId?: string;
+  taskIdPattern?: string;
+};
+
+type HITLDetailsOptions = {
+  refetchInterval?: number | false;
+};
+
+export const useHitlDetails = (params: HITLDetailsParams, options: HITLDetailsOptions = {}) => {
+  const { dagId, dagRunId, responseReceived, state, taskId, taskIdPattern } = params;
+  const { refetchInterval } = options;
+
+  // If there is a dagId, let's see if any tasks have HITL operators
+  const { data: tasksData } = useTaskServiceGetTasks({ dagId: dagId ?? "~" }, undefined, {
+    enabled: Boolean(dagId),
+  });
+
+  const hasHitlOperators = Boolean(
+    tasksData?.tasks.some((task) => {
+      const operatorName = task.operator_name;
+
+      // TODO: do this in the backend
+      return (
+        operatorName === "HITLOperator" ||
+        operatorName === "ApprovalOperator" ||
+        operatorName === "HITLEntryOperator" ||
+        operatorName === "HITLBranchOperator"
+      );

Review Comment:
   Do we want to merge this if this is incomplete for now? (Or should we tackle it from the backend instead, wdyt?)
   
   I'm afraid that this could remain like this for a while, and end up being wrong if people implement custom operators and such.
   
   Maybe we can just fetch the HITLs and disable the query if it returns empty data, so we stop refetching multiple times for no reasons. That might be easier than adding extra information in the backend endpoint.



-- 
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] Check if any tasks have HITL operator before fetching HITL details [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi closed pull request #56268: Check if any tasks have HITL operator before fetching HITL details
URL: https://github.com/apache/airflow/pull/56268


-- 
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] Check if any tasks have HITL operator before fetching HITL details [airflow]

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


##########
airflow-core/src/airflow/ui/src/queries/useHitlDetails.ts:
##########
@@ -0,0 +1,73 @@
+/*!
+ * 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 { useTaskInstanceServiceGetHitlDetails, useTaskServiceGetTasks } from "openapi/queries";
+
+type HITLDetailsParams = {
+  dagId?: string;
+  dagRunId?: string;
+  responseReceived?: boolean;
+  state?: Array<string>;
+  taskId?: string;
+  taskIdPattern?: string;
+};
+
+type HITLDetailsOptions = {
+  refetchInterval?: number | false;
+};
+
+export const useHitlDetails = (params: HITLDetailsParams, options: HITLDetailsOptions = {}) => {
+  const { dagId, dagRunId, responseReceived, state, taskId, taskIdPattern } = params;
+  const { refetchInterval } = options;
+
+  // If there is a dagId, let's see if any tasks have HITL operators
+  const { data: tasksData } = useTaskServiceGetTasks({ dagId: dagId ?? "~" }, undefined, {
+    enabled: Boolean(dagId),
+  });
+
+  const hasHitlOperators = Boolean(
+    tasksData?.tasks.some((task) => {
+      const operatorName = task.operator_name;
+
+      // TODO: do this in the backend
+      return (
+        operatorName === "HITLOperator" ||
+        operatorName === "ApprovalOperator" ||
+        operatorName === "HITLEntryOperator" ||
+        operatorName === "HITLBranchOperator"
+      );

Review Comment:
   Do we want to merge this if this is incomplete for now? (Or should we tackle it from the backend instead, wdyt?)
   
   I'm afraid that this could remain like this for a while, and end up being wrong if people implement custom operators and such.
   
   Maybe we can just fetch the HITLs and disable the query if it returns empty data, so we stop refecthing multiple times for no reasons.



-- 
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] Check if any tasks have HITL operator before fetching HITL details [airflow]

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


##########
airflow-core/src/airflow/ui/src/queries/useHitlDetails.ts:
##########
@@ -0,0 +1,73 @@
+/*!
+ * 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 { useTaskInstanceServiceGetHitlDetails, useTaskServiceGetTasks } from "openapi/queries";
+
+type HITLDetailsParams = {
+  dagId?: string;
+  dagRunId?: string;
+  responseReceived?: boolean;
+  state?: Array<string>;
+  taskId?: string;
+  taskIdPattern?: string;
+};
+
+type HITLDetailsOptions = {
+  refetchInterval?: number | false;
+};
+
+export const useHitlDetails = (params: HITLDetailsParams, options: HITLDetailsOptions = {}) => {
+  const { dagId, dagRunId, responseReceived, state, taskId, taskIdPattern } = params;
+  const { refetchInterval } = options;
+
+  // If there is a dagId, let's see if any tasks have HITL operators
+  const { data: tasksData } = useTaskServiceGetTasks({ dagId: dagId ?? "~" }, undefined, {
+    enabled: Boolean(dagId),
+  });
+
+  const hasHitlOperators = Boolean(
+    tasksData?.tasks.some((task) => {
+      const operatorName = task.operator_name;
+
+      // TODO: do this in the backend
+      return (
+        operatorName === "HITLOperator" ||
+        operatorName === "ApprovalOperator" ||
+        operatorName === "HITLEntryOperator" ||
+        operatorName === "HITLBranchOperator"
+      );

Review Comment:
   Alright, I'll close this and think about it some more.



-- 
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] Check if any tasks have HITL operator before fetching HITL details [airflow]

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


##########
airflow-core/src/airflow/ui/src/queries/useHitlDetails.ts:
##########
@@ -0,0 +1,73 @@
+/*!
+ * 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 { useTaskInstanceServiceGetHitlDetails, useTaskServiceGetTasks } from "openapi/queries";
+
+type HITLDetailsParams = {
+  dagId?: string;
+  dagRunId?: string;
+  responseReceived?: boolean;
+  state?: Array<string>;
+  taskId?: string;
+  taskIdPattern?: string;
+};
+
+type HITLDetailsOptions = {
+  refetchInterval?: number | false;
+};
+
+export const useHitlDetails = (params: HITLDetailsParams, options: HITLDetailsOptions = {}) => {
+  const { dagId, dagRunId, responseReceived, state, taskId, taskIdPattern } = params;
+  const { refetchInterval } = options;
+
+  // If there is a dagId, let's see if any tasks have HITL operators
+  const { data: tasksData } = useTaskServiceGetTasks({ dagId: dagId ?? "~" }, undefined, {
+    enabled: Boolean(dagId),
+  });
+
+  const hasHitlOperators = Boolean(
+    tasksData?.tasks.some((task) => {
+      const operatorName = task.operator_name;
+
+      // TODO: do this in the backend
+      return (
+        operatorName === "HITLOperator" ||
+        operatorName === "ApprovalOperator" ||
+        operatorName === "HITLEntryOperator" ||
+        operatorName === "HITLBranchOperator"
+      );

Review Comment:
   Do we want to merge this if this is incomplete for now? (Or should we tackle it from the backend instead, wdyt?)
   
   I'm afraid that this could remain like this for a while, and end up being wrong if people implement custom operators and such.
   
   Maybe we can just fetch the HITLs and disable the query if it returns no hitl once?



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