Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in query invalidation and remove custom predicate logic #46485

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions airflow/ui/src/queries/useTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from "openapi/queries";
import type { DagRunTriggerParams } from "src/components/TriggerDag/TriggerDAGForm";
import { toaster } from "src/components/ui";
import { doQueryKeysMatch, type PartialQueryKey } from "src/utils";

export const useTrigger = ({ dagId, onSuccessConfirm }: { dagId: string; onSuccessConfirm: () => void }) => {
const queryClient = useQueryClient();
Expand All @@ -37,14 +36,14 @@ export const useTrigger = ({ dagId, onSuccessConfirm }: { dagId: string; onSucce
const [dateValidationError, setDateValidationError] = useState<unknown>(undefined);

const onSuccess = async () => {
const queryKeys: Array<PartialQueryKey> = [
{ baseKey: useDagServiceGetDagsKey },
{ baseKey: useDagsServiceRecentDagRunsKey },
{ baseKey: useDagRunServiceGetDagRunsKey, options: { dagIds: [dagId] } },
{ baseKey: useTaskInstanceServiceGetTaskInstancesKey, options: { dagId, dagRunId: "~" } },
const queryKeys = [
[useDagServiceGetDagsKey],
[useDagsServiceRecentDagRunsKey],
[useDagRunServiceGetDagRunsKey, { dagId }],
[useTaskInstanceServiceGetTaskInstancesKey, { dagId, dagRunId: "~" }],
];

await queryClient.invalidateQueries({ predicate: (query) => doQueryKeysMatch(query, queryKeys) });
await Promise.all(queryKeys.map((key) => queryClient.invalidateQueries({ queryKey: key })));

toaster.create({
description: "DAG run has been successfully triggered.",
Expand Down
22 changes: 0 additions & 22 deletions airflow/ui/src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { Query } from "@tanstack/react-query";

import { useDagServiceGetDagDetails } from "openapi/queries";
import type { TaskInstanceState } from "openapi/requests/types.gen";
import { useConfig } from "src/queries/useConfig";
Expand All @@ -32,26 +30,6 @@ export const isStatePending = (state?: TaskInstanceState | null) =>
state === "restarting" ||
!Boolean(state);

export type PartialQueryKey = { baseKey: string; options?: Record<string, unknown> };

// This allows us to specify what query key values we actually care about and ignore the rest
// ex: match everything with this dagId and dagRunId but ignore anything related to pagination
export const doQueryKeysMatch = (query: Query, queryKeysToMatch: Array<PartialQueryKey>) => {
const [baseKey, options] = query.queryKey;

const matchedKey = queryKeysToMatch.find((qk) => qk.baseKey === baseKey);

if (!matchedKey) {
return false;
}

return matchedKey.options
? Object.entries(matchedKey.options).every(
([key, value]) => typeof options === "object" && (options as Record<string, unknown>)[key] === value,
)
: true;
};

export const useAutoRefresh = ({ dagId, isPaused }: { dagId?: string; isPaused?: boolean }) => {
const autoRefreshInterval = useConfig("auto_refresh_interval") as number | undefined;
const { data: dag } = useDagServiceGetDagDetails(
Expand Down