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

[PR] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

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

   <!--
    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.
    -->
   
   ## Fix DagVersionSelect filtering to show only versions compatible with selected DagRun
   
   This PR fixes the DagVersionSelect component in the Graph view to filter available versions based on the currently selected DagRun, preventing users from selecting incompatible version/DagRun combinations that cause confusion.
   
   ### Problem
   When viewing a DAG's Graph view, users could select any DAG version regardless of which DagRun was selected. This led to confusing scenarios where the selected version wasn't actually part of the displayed DagRun's `dag_versions` array, causing inconsistent data presentation.
   
   ### Solution
   - **Filter versions by DagRun**: When a specific DagRun is selected, only show versions that exist in that DagRun's `dag_versions` array
   - **Auto-clear incompatible selections**: Automatically clear version selection when switching to a DagRun that doesn't contain the currently selected version
   - **Maintain backward compatibility**: When no DagRun is selected, continue showing all available DAG versions
   - **Improve UX**: Prevent confusing version/DagRun combinations and provide clearer user guidance
   
   ### Changes Made
   1. **Enhanced DagVersionSelect component**:
      - Added `useDagRunServiceGetDagRun` hook to fetch current DagRun data
      - Implemented `availableVersions` filtering logic using `useMemo`
      - Added `useEffect` to auto-clear incompatible version selections
      - Updated component disabled state to handle filtered results
   
   2. **Key Logic**:
      ```typescript
      // Filter versions based on selected DagRun
      const availableVersions = useMemo(() => {
        if (!data?.dag_versions) return [];
        
        // If a DagRun is selected, only show versions that are part of that DagRun
        if (dagRunData?.dag_versions) {
          const dagRunVersionNumbers = new Set(
            dagRunData.dag_versions.map(v => v.version_number)
          );
          return data.dag_versions.filter(v => 
            dagRunVersionNumbers.has(v.version_number)
          );
        }
        
        // If no DagRun is selected, show all versions
        return data.dag_versions;
      }, [data?.dag_versions, dagRunData?.dag_versions]);
      ```
   
   ---
   
   closes: #51487
   
   


-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

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


##########
airflow-core/src/airflow/ui/src/components/DagVersionSelect.tsx:
##########
@@ -35,18 +38,55 @@ type VersionSelected = {
 
 export const DagVersionSelect = ({ showLabel = true }: { readonly showLabel?: boolean }) => {
   const { t: translate } = useTranslation("components");
-  const { dagId = "" } = useParams();
+  const { dagId = "", runId } = useParams();
   const { data, isLoading } = useDagVersionServiceGetDagVersions({ dagId, orderBy: "-version_number" });
+  
+  const { data: dagRunData } = useDagRunServiceGetDagRun(
+    {
+      dagId,
+      dagRunId: runId ?? "",
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) },
+  );
+  
   const [searchParams, setSearchParams] = useSearchParams();
   const selectedVersionNumber = useSelectedVersion();
-  const selectedVersion = data?.dag_versions.find((dv) => dv.version_number === selectedVersionNumber);
+  
+  const availableVersions = useMemo(() => {
+    if (!data?.dag_versions) return [];
+    
+    if (dagRunData?.dag_versions) {
+      const dagRunVersionNumbers = new Set(
+        dagRunData.dag_versions.map((v: DagVersionResponse) => v.version_number)
+      );

Review Comment:
   You do not need a set. The backend is taking care of returning the unique versions list involved in the DagRun.



-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

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


##########
airflow-core/src/airflow/ui/src/components/DagVersionSelect.tsx:
##########
@@ -35,18 +38,55 @@ type VersionSelected = {
 
 export const DagVersionSelect = ({ showLabel = true }: { readonly showLabel?: boolean }) => {
   const { t: translate } = useTranslation("components");
-  const { dagId = "" } = useParams();
+  const { dagId = "", runId } = useParams();
   const { data, isLoading } = useDagVersionServiceGetDagVersions({ dagId, orderBy: "-version_number" });
+  
+  const { data: dagRunData } = useDagRunServiceGetDagRun(
+    {
+      dagId,
+      dagRunId: runId ?? "",
+    },
+    undefined,
+    { enabled: Boolean(dagId) && Boolean(runId) },
+  );
+  
   const [searchParams, setSearchParams] = useSearchParams();
   const selectedVersionNumber = useSelectedVersion();
-  const selectedVersion = data?.dag_versions.find((dv) => dv.version_number === selectedVersionNumber);
+  
+  const availableVersions = useMemo(() => {
+    if (!data?.dag_versions) return [];
+    
+    if (dagRunData?.dag_versions) {
+      const dagRunVersionNumbers = new Set(
+        dagRunData.dag_versions.map((v: DagVersionResponse) => v.version_number)
+      );

Review Comment:
   Hey @pierrejeambrun Thanks. I think I should remove this set thing and proceed with a much simpler approach.



-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #51534:
URL: https://github.com/apache/airflow/pull/51534#issuecomment-3289176359

   @krikera are you still working on this PR?


-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #51534:
URL: https://github.com/apache/airflow/pull/51534#issuecomment-3745015559

   Stale PR, closing


-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #51534:
URL: https://github.com/apache/airflow/pull/51534#issuecomment-3127479325

   @krikera Were you able to make progress on that ? I see comments from last review were not addressed, do you need help? 


-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

Posted by "krikera (via GitHub)" <gi...@apache.org>.
krikera commented on PR #51534:
URL: https://github.com/apache/airflow/pull/51534#issuecomment-2959470550

   > Good idea. I wonder if this would be easier to just pass the dagrun.dag_versions to the dropdown if a dagrun is selected instead of filtering data.dag_versions?
   > 
   > Is there any information missing in the dagrun versions?
   
   You're absolutely right about using `dagrun.dag_versions` directly and the sorting issue. That's a much cleaner approach.


-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #51534:
URL: https://github.com/apache/airflow/pull/51534#issuecomment-2955986511

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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] fix: Filter DagVersionSelect options based on selected DagRun [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun closed pull request #51534: fix: Filter DagVersionSelect options based on selected DagRun
URL: https://github.com/apache/airflow/pull/51534


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