diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts index 95f8fa54eed..1bcf3a1e856 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts @@ -44,16 +44,20 @@ export interface UsePolicyVersionsOptions { enabled?: boolean; } +/** Stable key used when the query is disabled to avoid undefined in cache keys. */ +const DISABLED_POLICY_KEY = "__disabled__"; + export const usePolicyVersions = ({ policyName, enabled = true, }: UsePolicyVersionsOptions) => { const { accessToken } = useAuthorized(); + const isEnabled = Boolean(accessToken && policyName && enabled); return useQuery({ - queryKey: policyVersionKeys.detail(policyName!), + queryKey: policyVersionKeys.detail(policyName ?? DISABLED_POLICY_KEY), queryFn: async () => await fetchPolicyVersions(accessToken!, policyName!), - enabled: Boolean(accessToken && policyName && enabled), + enabled: isEnabled, select: (data) => ({ ...data, versions: data.versions ?? [], diff --git a/ui/litellm-dashboard/src/components/policies/pipeline_flow_builder.tsx b/ui/litellm-dashboard/src/components/policies/pipeline_flow_builder.tsx index 3e2d55207be..7d1802749c6 100644 --- a/ui/litellm-dashboard/src/components/policies/pipeline_flow_builder.tsx +++ b/ui/litellm-dashboard/src/components/policies/pipeline_flow_builder.tsx @@ -1316,12 +1316,13 @@ export const FlowBuilderPage: React.FC = ({ const updateStatusMutation = useUpdatePolicyVersionStatus(editingPolicy?.policy_name); const handleNewVersion = async () => { + let newPolicy: Policy; try { - const newPolicy = await createVersionMutation.mutateAsync(); - onVersionCreated?.(newPolicy); + newPolicy = await createVersionMutation.mutateAsync(); } catch { - // Notification already shown by onError in the mutation hook + return; // Notification already shown by onError in the mutation hook } + onVersionCreated?.(newPolicy); }; const handleSelectVersion = (policy: Policy) => { @@ -1330,28 +1331,30 @@ export const FlowBuilderPage: React.FC = ({ const handlePublishVersion = async () => { if (!editingPolicy?.policy_id) return; + let updated: Policy; try { - const updated = await updateStatusMutation.mutateAsync({ + updated = await updateStatusMutation.mutateAsync({ policyId: editingPolicy.policy_id, status: "published", }); - onVersionStatusUpdated?.(updated); } catch { - // Notification already shown by onError in the mutation hook + return; // Notification already shown by onError in the mutation hook } + onVersionStatusUpdated?.(updated); }; const handlePromoteToProduction = async () => { if (!editingPolicy?.policy_id) return; + let updated: Policy; try { - const updated = await updateStatusMutation.mutateAsync({ + updated = await updateStatusMutation.mutateAsync({ policyId: editingPolicy.policy_id, status: "production", }); - onVersionStatusUpdated?.(updated); } catch { - // Notification already shown by onError in the mutation hook + return; // Notification already shown by onError in the mutation hook } + onVersionStatusUpdated?.(updated); }; const handleSave = async () => {