Skip to content

Commit 2c3b459

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

File tree

10 files changed

+360
-25
lines changed

10 files changed

+360
-25
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useBackend } from "@/providers/BackendProvider";
88
import { getExecutionArtifacts } from "@/services/executionService";
99
import { getBackendStatusString } from "@/utils/backend";
1010
import type { TaskSpec } from "@/utils/componentSpec";
11+
import { BACKEND_QUERY_KEY } from "@/utils/constants";
1112

1213
import IOExtras from "./IOExtras";
1314
import IOInputs from "./IOInputs";
@@ -28,9 +29,9 @@ const IOSection = ({ taskSpec, executionId, readOnly }: IOSectionProps) => {
2829
isFetching,
2930
error,
3031
} = useQuery({
31-
queryKey: ["artifacts", executionId],
32+
queryKey: [BACKEND_QUERY_KEY, "artifacts", executionId],
3233
queryFn: () => getExecutionArtifacts(String(executionId), backendUrl),
33-
enabled: !!executionId,
34+
enabled: !!executionId && !!backendUrl,
3435
});
3536

3637
if (!configured) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Spinner } from "@/components/ui/spinner";
99
import { useBackend } from "@/providers/BackendProvider";
1010
import type { RunStatus } from "@/types/pipelineRun";
1111
import { getBackendStatusString } from "@/utils/backend";
12+
import { BACKEND_QUERY_KEY } from "@/utils/constants";
1213

1314
const LogDisplay = ({
1415
logs,
@@ -114,10 +115,10 @@ const Logs = ({
114115
log_text?: string;
115116
system_error_exception_full?: string;
116117
}>();
117-
const { data, isLoading, error, refetch } = useQuery({
118-
queryKey: ["logs", executionId],
118+
const { data, isLoading, error } = useQuery({
119+
queryKey: [BACKEND_QUERY_KEY, "logs", executionId],
119120
queryFn: () => getLogs(String(executionId), backendUrl),
120-
enabled: isLogging,
121+
enabled: isLogging && !!backendUrl,
121122
refetchInterval: 5000,
122123
refetchIntervalInBackground: false,
123124
});
@@ -142,10 +143,6 @@ const Logs = ({
142143
}
143144
}, [data, error]);
144145

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

src/hooks/usePipelineRunData.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import {
1010
getRunStatus,
1111
isStatusComplete,
1212
} from "@/services/executionService";
13+
import { BACKEND_QUERY_KEY } from "@/utils/constants";
1314

1415
const useRootExecutionId = (id: string) => {
1516
const { backendUrl } = useBackend();
1617
const { data: rootExecutionId } = useQuery({
17-
queryKey: ["pipeline-run-execution-id", id],
18+
queryKey: [BACKEND_QUERY_KEY, "pipeline-run-execution-id", id],
1819
queryFn: async () => {
1920
const rootExecutionId = await fetchPipelineRun(id, backendUrl)
2021
.then((res) => res.root_execution_id)
@@ -27,7 +28,7 @@ const useRootExecutionId = (id: string) => {
2728
// assuming id is root_execution_id
2829
return id;
2930
},
30-
enabled: !!id && id.length > 0,
31+
enabled: !!id && id.length > 0 && !!backendUrl,
3132
staleTime: Infinity,
3233
});
3334

@@ -41,8 +42,8 @@ export const usePipelineRunData = (id: string) => {
4142
const rootExecutionId = useRootExecutionId(id);
4243

4344
const { data: executionDetails } = useQuery({
44-
enabled: !!rootExecutionId,
45-
queryKey: ["execution-details", rootExecutionId],
45+
enabled: !!rootExecutionId && !!backendUrl,
46+
queryKey: [BACKEND_QUERY_KEY, "execution-details", rootExecutionId],
4647
queryFn: async () => {
4748
if (!rootExecutionId) {
4849
throw new Error("No root execution id found");
@@ -58,8 +59,8 @@ export const usePipelineRunData = (id: string) => {
5859
error,
5960
isLoading,
6061
} = useQuery({
61-
enabled: !!rootExecutionId && !!executionDetails,
62-
queryKey: ["pipeline-run", rootExecutionId],
62+
enabled: !!rootExecutionId && !!executionDetails && !!backendUrl,
63+
queryKey: [BACKEND_QUERY_KEY, "pipeline-run", rootExecutionId],
6364
queryFn: async () => {
6465
if (!rootExecutionId) {
6566
throw new Error("No root execution id found");

src/hooks/useSubgraphBreadcrumbs.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useMemo } from "react";
44
import { useBackend } from "@/providers/BackendProvider";
55
import { fetchExecutionDetails } from "@/services/executionService";
66
import { isGraphImplementationOutput } from "@/utils/componentSpec";
7-
import { ONE_MINUTE_IN_MS } from "@/utils/constants";
7+
import { BACKEND_QUERY_KEY, ONE_MINUTE_IN_MS } from "@/utils/constants";
88

99
export interface BreadcrumbSegment {
1010
taskId: string;
@@ -31,7 +31,12 @@ export const useSubgraphBreadcrumbs = (
3131
const queryClient = useQueryClient();
3232

3333
const { data, isLoading, error } = useQuery({
34-
queryKey: ["subgraph-breadcrumbs", rootExecutionId, subgraphExecutionId],
34+
queryKey: [
35+
BACKEND_QUERY_KEY,
36+
"subgraph-breadcrumbs",
37+
rootExecutionId,
38+
subgraphExecutionId,
39+
],
3540
queryFn: async () => {
3641
if (!rootExecutionId || !subgraphExecutionId) {
3742
return { segments: [] };
@@ -44,7 +49,7 @@ export const useSubgraphBreadcrumbs = (
4449
const segmentsInReverseOrder: BreadcrumbSegment[] = [];
4550
let currentExecutionId = subgraphExecutionId;
4651
let currentDetails = await queryClient.ensureQueryData({
47-
queryKey: ["execution-details", currentExecutionId],
52+
queryKey: [BACKEND_QUERY_KEY, "execution-details", currentExecutionId],
4853
queryFn: () => fetchExecutionDetails(currentExecutionId, backendUrl),
4954
staleTime: ONE_MINUTE_IN_MS,
5055
});
@@ -57,7 +62,7 @@ export const useSubgraphBreadcrumbs = (
5762
}
5863

5964
const parentDetails = await queryClient.ensureQueryData({
60-
queryKey: ["execution-details", parentExecutionId],
65+
queryKey: [BACKEND_QUERY_KEY, "execution-details", parentExecutionId],
6166
queryFn: () => fetchExecutionDetails(parentExecutionId, backendUrl),
6267
staleTime: ONE_MINUTE_IN_MS,
6368
});
@@ -95,7 +100,8 @@ export const useSubgraphBreadcrumbs = (
95100
enabled:
96101
!!rootExecutionId &&
97102
!!subgraphExecutionId &&
98-
rootExecutionId !== subgraphExecutionId,
103+
rootExecutionId !== subgraphExecutionId &&
104+
!!backendUrl,
99105
staleTime: ONE_MINUTE_IN_MS,
100106
retry: 1,
101107
});

0 commit comments

Comments
 (0)