Skip to content

Commit b530eca

Browse files
committed
fix: Querying data unreliable with custom backend
1 parent 4cc6d0b commit b530eca

File tree

8 files changed

+75
-15
lines changed

8 files changed

+75
-15
lines changed

src/components/Home/RunSection/RunSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const RunSection = ({ onEmptyList }: { onEmptyList?: () => void }) => {
7575

7676
const { data, isLoading, isFetching, error, isFetched } =
7777
useQuery<ListPipelineJobsResponse>({
78-
queryKey: ["runs", backendUrl, pageToken, search.filter],
78+
queryKey: ["runs", pageToken, search.filter],
7979
refetchOnWindowFocus: false,
8080
enabled: configured && available,
8181
queryFn: async () => {

src/components/PipelineRun/RunDetails.test.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ describe("<RunDetails/>", () => {
6565
},
6666
});
6767

68+
const MOCK_BACKEND_URL = "http://localhost:8000";
69+
6870
const mockExecutionDetails: GetExecutionInfoResponse = {
6971
id: "test-execution-id",
7072
pipeline_run_id: "123",
@@ -158,7 +160,7 @@ describe("<RunDetails/>", () => {
158160
configured: true,
159161
available: true,
160162
ready: true,
161-
backendUrl: "http://localhost:8000",
163+
backendUrl: MOCK_BACKEND_URL,
162164
isConfiguredFromEnv: false,
163165
isConfiguredFromRelativePath: false,
164166
setEnvConfig: vi.fn(),
@@ -189,6 +191,50 @@ describe("<RunDetails/>", () => {
189191
});
190192
};
191193

194+
describe("Backend Configuration", () => {
195+
test("should render run details when backend is configured", async () => {
196+
// The default mock has configured: true and backendUrl: MOCK_BACKEND_URL
197+
// act
198+
renderWithProviders(<RunDetails />);
199+
200+
// assert
201+
await waitFor(() => {
202+
expect(screen.getByText("Test Pipeline")).toBeInTheDocument();
203+
expect(screen.getByText("Run Id:")).toBeInTheDocument();
204+
expect(screen.getByText("123")).toBeInTheDocument();
205+
});
206+
});
207+
208+
test("should render run details when backendUrl is empty string", async () => {
209+
// arrange - simulate custom backend toggle disabled (empty backendUrl)
210+
vi.mocked(useBackend).mockReturnValue({
211+
configured: true,
212+
available: true,
213+
ready: true,
214+
backendUrl: "",
215+
isConfiguredFromEnv: false,
216+
isConfiguredFromRelativePath: true,
217+
setEnvConfig: vi.fn(),
218+
setRelativePathConfig: vi.fn(),
219+
setBackendUrl: vi.fn(),
220+
ping: vi.fn(),
221+
});
222+
223+
// Query key no longer includes backendUrl - cache is shared regardless of URL
224+
// and invalidated when backend URL changes
225+
226+
// act
227+
renderWithProviders(<RunDetails />);
228+
229+
// assert
230+
await waitFor(() => {
231+
expect(screen.getByText("Test Pipeline")).toBeInTheDocument();
232+
expect(screen.getByText("Run Id:")).toBeInTheDocument();
233+
expect(screen.getByText("123")).toBeInTheDocument();
234+
});
235+
});
236+
});
237+
192238
describe("Inspect Pipeline Button", () => {
193239
test("should render inspect button when pipeline exists", async () => {
194240
// arrange

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskOverview/IOSection/IOSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const IOSection = ({ taskSpec, executionId, readOnly }: IOSectionProps) => {
3030
} = useQuery({
3131
queryKey: ["artifacts", executionId],
3232
queryFn: () => getExecutionArtifacts(String(executionId), backendUrl),
33-
enabled: !!executionId,
33+
enabled: !!executionId && !!backendUrl,
3434
});
3535

3636
if (!configured) {

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskOverview/logs.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ const Logs = ({
114114
log_text?: string;
115115
system_error_exception_full?: string;
116116
}>();
117-
const { data, isLoading, error, refetch } = useQuery({
117+
const { data, isLoading, error } = useQuery({
118118
queryKey: ["logs", executionId],
119119
queryFn: () => getLogs(String(executionId), backendUrl),
120-
enabled: isLogging,
120+
enabled: isLogging && !!backendUrl,
121121
refetchInterval: 5000,
122122
refetchIntervalInBackground: false,
123123
});
@@ -142,10 +142,6 @@ const Logs = ({
142142
}
143143
}, [data, error]);
144144

145-
useEffect(() => {
146-
refetch();
147-
}, [backendUrl, refetch]);
148-
149145
if (!configured) {
150146
return (
151147
<InfoBox title="Backend not configured" variant="warning">

src/hooks/usePipelineRunData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const useRootExecutionId = (id: string) => {
2727
// assuming id is root_execution_id
2828
return id;
2929
},
30-
enabled: !!id && id.length > 0,
30+
enabled: !!id && id.length > 0 && !!backendUrl,
3131
staleTime: Infinity,
3232
});
3333

@@ -41,7 +41,7 @@ export const usePipelineRunData = (id: string) => {
4141
const rootExecutionId = useRootExecutionId(id);
4242

4343
const { data: executionDetails } = useQuery({
44-
enabled: !!rootExecutionId,
44+
enabled: !!rootExecutionId && !!backendUrl,
4545
queryKey: ["execution-details", rootExecutionId],
4646
queryFn: async () => {
4747
if (!rootExecutionId) {
@@ -58,7 +58,7 @@ export const usePipelineRunData = (id: string) => {
5858
error,
5959
isLoading,
6060
} = useQuery({
61-
enabled: !!rootExecutionId && !!executionDetails,
61+
enabled: !!rootExecutionId && !!executionDetails && !!backendUrl,
6262
queryKey: ["pipeline-run", rootExecutionId],
6363
queryFn: async () => {
6464
if (!rootExecutionId) {

src/hooks/useSubgraphBreadcrumbs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export const useSubgraphBreadcrumbs = (
9595
enabled:
9696
!!rootExecutionId &&
9797
!!subgraphExecutionId &&
98-
rootExecutionId !== subgraphExecutionId,
98+
rootExecutionId !== subgraphExecutionId &&
99+
!!backendUrl,
99100
staleTime: ONE_MINUTE_IN_MS,
100101
retry: 1,
101102
});

src/providers/BackendProvider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { useQueryClient } from "@tanstack/react-query";
12
import {
23
type ReactNode,
34
useCallback,
45
useEffect,
56
useMemo,
7+
useRef,
68
useState,
79
} from "react";
810

@@ -45,6 +47,7 @@ const BackendContext =
4547

4648
export const BackendProvider = ({ children }: { children: ReactNode }) => {
4749
const notify = useToastNotification();
50+
const queryClient = useQueryClient();
4851

4952
const backendUrlFromEnv = API_URL;
5053

@@ -55,6 +58,9 @@ export const BackendProvider = ({ children }: { children: ReactNode }) => {
5558
const [settingsLoaded, setSettingsLoaded] = useState(false);
5659
const [ready, setReady] = useState(false);
5760

61+
// Track the previous backend URL to detect changes
62+
const previousBackendUrlRef = useRef<string | null>(null);
63+
5864
let backendUrl = "";
5965
if (useEnv && backendUrlFromEnv) {
6066
backendUrl = backendUrlFromEnv;
@@ -133,6 +139,17 @@ export const BackendProvider = ({ children }: { children: ReactNode }) => {
133139
}
134140
}, [backendUrl, settingsLoaded]);
135141

142+
// Invalidate all queries when the backend URL changes
143+
useEffect(() => {
144+
if (
145+
previousBackendUrlRef.current !== null &&
146+
previousBackendUrlRef.current !== backendUrl
147+
) {
148+
queryClient.invalidateQueries();
149+
}
150+
previousBackendUrlRef.current = backendUrl;
151+
}, [backendUrl, queryClient]);
152+
136153
useEffect(() => {
137154
const getSettings = async () => {
138155
const url = await getUserBackendUrl();

src/services/executionService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const useFetchPipelineRunMetadata = (runId: string | undefined) => {
5050
return useQuery<PipelineRunResponse>({
5151
queryKey: ["pipeline-run-metadata", runId],
5252
queryFn: () => fetchPipelineRun(runId!, backendUrl),
53-
enabled: !!runId,
53+
enabled: !!runId && !!backendUrl,
5454
refetchOnWindowFocus: false,
5555
staleTime: TWENTY_FOUR_HOURS_IN_MS,
5656
});
@@ -71,7 +71,7 @@ export const useFetchContainerExecutionState = (
7171
return useQuery<GetContainerExecutionStateResponse>({
7272
queryKey: ["container-execution-state", executionId],
7373
queryFn: () => fetchContainerExecutionState(executionId!, backendUrl),
74-
enabled: !!executionId,
74+
enabled: !!executionId && !!backendUrl,
7575
refetchOnWindowFocus: false,
7676
});
7777
};

0 commit comments

Comments
 (0)