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

bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 32550ea56b6 UI: Send the hide-paused default with the first Dags list 
request (#76689)
32550ea56b6 is described below

commit 32550ea56b65bc3770371105ac56603fccb8f9bd
Author: Shahar Epstein <[email protected]>
AuthorDate: Tue Nov 17 20:29:44 2026 +0200

    UI: Send the hide-paused default with the first Dags list request (#76689)
    
    * UI: Send the hide-paused default with the first Dags list request
    
    With ``hide_paused_dags_by_default`` enabled the Dags list fetched twice on
    every page load: the paused default was written into the URL from an effect,
    after the first ``/ui/dags`` request had already gone out unfiltered. Paused
    Dags flashed into the list until the second response replaced them, and the
    ``DagsFilters`` test that waits for them to disappear raced that second
    request and failed intermittently in CI.
    
    The list now derives the pending default during render, so the first request
    already carries ``paused=false`` and the URL seed produces the same query 
key.
    
    Claude-Session: https://claude.ai/code/session_01BVx6g7GpQFxdabhHVW6KYd
    
    * Use the defined paused default instead of hardcoded values
    
    Address review feedback: usePausedDefault now returns the default paused
    state itself rather than a flag, the URL seed is written through
    pausedStateToSearchParams, the functional updater leaves an existing
    paused or scheduling_state filter untouched, and the test asserts that
    exactly one Dags list request is sent.
    
    Claude-Session: https://claude.ai/code/session_01BVx6gARFVCg8fLbs1Zfy4h
---
 .../DagsList/DagsFilters/DagsFilters.test.tsx      | 23 ++++++++++-
 .../src/pages/DagsList/DagsFilters/DagsFilters.tsx |  4 --
 .../src/airflow/ui/src/pages/DagsList/DagsList.tsx |  5 ++-
 .../ui/src/pages/DagsList/usePausedDefault.ts      | 47 +++++++++++++++++-----
 4 files changed, 62 insertions(+), 17 deletions(-)

diff --git 
a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.test.tsx
 
b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.test.tsx
index 289a63b3012..85fe418853a 100644
--- 
a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.test.tsx
+++ 
b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.test.tsx
@@ -75,6 +75,27 @@ describe("Paused filter with hide_paused_dags_by_default 
enabled", () => {
     });
   });
 
+  it("sends the paused default on every dags request, including the first", 
async () => {
+    const urls: Array<URL> = [];
+    const onRequest = ({ request }: { request: Request }) => {
+      urls.push(new URL(request.url));
+    };
+
+    server.events.on("request:start", onRequest);
+    try {
+      render(<AppWrapper initialEntries={["/dags"]} />);
+
+      await waitFor(() => 
expect(screen.getByText("tutorial_taskflow_api_success")).toBeInTheDocument());
+    } finally {
+      server.events.removeListener("request:start", onRequest);
+    }
+
+    const dagsRequests = urls.filter((url) => url.pathname === "/ui/dags");
+
+    expect(dagsRequests).toHaveLength(1);
+    expect(dagsRequests.every((url) => url.searchParams.get("paused") === 
"false")).toBe(true);
+  });
+
   it("keeps draining dags under the default, since they are not paused yet", 
async () => {
     withDrainingDag();
     render(<AppWrapper initialEntries={["/dags"]} />);
@@ -133,7 +154,7 @@ describe("Paused filter with hide_paused_dags_by_default 
enabled", () => {
     });
 
     // There is no "All" option any more; removing the pill is how you ask for 
every Dag.
-    fireEvent.click(screen.getByTestId("paused-pill-remove"));
+    fireEvent.click(await screen.findByTestId("paused-pill-remove"));
 
     await waitFor(() => 
expect(screen.getByText("paused_dag")).toBeInTheDocument());
     
expect(screen.getByText("tutorial_taskflow_api_success")).toBeInTheDocument();
diff --git 
a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.tsx 
b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.tsx
index 785c5637221..f4b5555b74f 100644
--- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.tsx
+++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsFilters/DagsFilters.tsx
@@ -22,13 +22,9 @@ import { SearchParamsKeys } from 
"src/constants/searchParams";
 import { useConfig } from "src/queries/useConfig";
 import { useFiltersHandler, type FilterableSearchParamsKeys } from "src/utils";
 
-import { usePausedDefault } from "../usePausedDefault";
-
 export const DagsFilters = () => {
   const multiTeamEnabled = Boolean(useConfig("multi_team"));
 
-  usePausedDefault();
-
   const searchParamKeys: Array<FilterableSearchParamsKeys> = [
     SearchParamsKeys.PAUSED,
     SearchParamsKeys.RUN_STATE,
diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx 
b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx
index 852285783dc..a1dcdce4d1c 100644
--- a/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx
+++ b/airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx
@@ -61,6 +61,7 @@ import { createColumns, getRowKey } from "./DagsListColumns";
 import { DagsListCountsProvider, useDagsListCounts, type RunStateCounts } from 
"./DagsListCountsContext";
 import { SortSelect } from "./SortSelect";
 import { MAX_RECENT_RUNS } from "./recentRunsLayout";
+import { usePausedDefault } from "./usePausedDefault";
 
 const {
   DAG_BUNDLE,
@@ -162,7 +163,9 @@ export const DagsList = () => {
   const multiTeamEnabled = Boolean(useConfig("multi_team"));
 
   // Derived through the pill's own mapping so the query can never filter on 
more than the pill shows.
-  const { paused, schedulingState } = 
pausedStateToQuery(pausedStateFromSearchParams(searchParams));
+  const pausedDefault = usePausedDefault();
+  const pausedState = pausedStateFromSearchParams(searchParams) ?? 
pausedDefault;
+  const { paused, schedulingState } = pausedStateToQuery(pausedState);
   const showFavorites = searchParams.get(FAVORITE);
   const importErrors = searchParams.get(HAS_IMPORT_ERRORS);
 
diff --git a/airflow-core/src/airflow/ui/src/pages/DagsList/usePausedDefault.ts 
b/airflow-core/src/airflow/ui/src/pages/DagsList/usePausedDefault.ts
index 967b0cff0e8..73265332429 100644
--- a/airflow-core/src/airflow/ui/src/pages/DagsList/usePausedDefault.ts
+++ b/airflow-core/src/airflow/ui/src/pages/DagsList/usePausedDefault.ts
@@ -16,48 +16,73 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { useEffect, useRef } from "react";
+import { useEffect, useState } from "react";
 
 import { useSearchParams } from "react-router-dom";
 
+import {
+  pausedStateToSearchParams,
+  type PausedStateValue,
+} from "src/components/FilterBar/filters/pausedStateParams";
+
 import { SearchParamsKeys } from "src/constants/searchParams";
 import { useConfig } from "src/queries/useConfig";
 
+const HIDE_PAUSED_DEFAULT: PausedStateValue = "not_paused";
+
+const hasPausedFilter = (params: URLSearchParams) =>
+  params.has(SearchParamsKeys.PAUSED) || 
params.has(SearchParamsKeys.SCHEDULING_STATE);
+
 /**
  * Writes the ``hide_paused_dags_by_default`` default into the URL so it shows 
up as a
  * pill instead of filtering invisibly.
  *
  * Seeds once per page load. Removing the pill is how you ask to see paused 
Dags, so re-seeding
  * whenever the param goes missing would put it straight back and leave them 
unreachable.
+ *
+ * Returns the default paused state until it is in the URL, so callers can 
query with it from the first render.
+ * ``hasSeeded`` flips only once the URL carries a filter: flipping it when 
the write is issued would
+ * leave a render with neither the param nor the pending flag, and fire an 
unfiltered request.
  */
 export const usePausedDefault = () => {
   const hidePausedDagsByDefault = 
Boolean(useConfig("hide_paused_dags_by_default"));
   const [searchParams, setSearchParams] = useSearchParams();
-  const hasSeeded = useRef(false);
+  const [hasSeeded, setHasSeeded] = useState(false);
 
   useEffect(() => {
-    if (
-      hasSeeded.current ||
-      !hidePausedDagsByDefault ||
-      searchParams.has(SearchParamsKeys.PAUSED) ||
-      searchParams.has(SearchParamsKeys.SCHEDULING_STATE)
-    ) {
+    if (hasSeeded || !hidePausedDagsByDefault) {
       return;
     }
 
-    hasSeeded.current = true;
+    if (hasPausedFilter(searchParams)) {
+      setHasSeeded(true);
+
+      return;
+    }
 
     // Functional form is required: PresetFiltersMenu restores a default 
preset from a
     // deeper effect that commits first, so an object write would clobber it 
with stale params.
     setSearchParams(
       (prev) => {
+        if (hasPausedFilter(prev)) {
+          return prev;
+        }
+
         const next = new URLSearchParams(prev);
 
-        next.set(SearchParamsKeys.PAUSED, "false");
+        
Object.entries(pausedStateToSearchParams(HIDE_PAUSED_DEFAULT)).forEach(([key, 
value]) => {
+          if (value !== undefined) {
+            next.set(key, value);
+          }
+        });
 
         return next;
       },
       { replace: true },
     );
-  }, [hidePausedDagsByDefault, searchParams, setSearchParams]);
+  }, [hasSeeded, hidePausedDagsByDefault, searchParams, setSearchParams]);
+
+  return hidePausedDagsByDefault && !hasSeeded && 
!hasPausedFilter(searchParams)
+    ? HIDE_PAUSED_DEFAULT
+    : undefined;
 };

Reply via email to