Skip to content

Commit da96890

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

File tree

7 files changed

+88
-27
lines changed

7 files changed

+88
-27
lines changed

src/components/PipelineRun/RunDetails.test.tsx

Lines changed: 57 additions & 3 deletions
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",
@@ -136,7 +138,10 @@ describe("<RunDetails/>", () => {
136138
error: null,
137139
});
138140

139-
queryClient.setQueryData(["pipeline-run-metadata", "123"], mockPipelineRun);
141+
queryClient.setQueryData(
142+
["pipeline-run-metadata", "123", MOCK_BACKEND_URL],
143+
mockPipelineRun,
144+
);
140145

141146
vi.mocked(executionService.countTaskStatuses).mockReturnValue({
142147
total: 2,
@@ -158,7 +163,7 @@ describe("<RunDetails/>", () => {
158163
configured: true,
159164
available: true,
160165
ready: true,
161-
backendUrl: "http://localhost:8000",
166+
backendUrl: MOCK_BACKEND_URL,
162167
isConfiguredFromEnv: false,
163168
isConfiguredFromRelativePath: false,
164169
setEnvConfig: vi.fn(),
@@ -189,6 +194,55 @@ describe("<RunDetails/>", () => {
189194
});
190195
};
191196

197+
describe("Backend Configuration", () => {
198+
test("should render run details when backend is configured", async () => {
199+
// The default mock has configured: true and backendUrl: MOCK_BACKEND_URL
200+
// act
201+
renderWithProviders(<RunDetails />);
202+
203+
// assert
204+
await waitFor(() => {
205+
expect(screen.getByText("Test Pipeline")).toBeInTheDocument();
206+
expect(
207+
screen.queryByText("Backend not configured"),
208+
).not.toBeInTheDocument();
209+
});
210+
});
211+
212+
test("should render run details when backendUrl is empty string", async () => {
213+
// arrange - simulate custom backend toggle disabled (empty backendUrl)
214+
vi.mocked(useBackend).mockReturnValue({
215+
configured: true,
216+
available: true,
217+
ready: true,
218+
backendUrl: "",
219+
isConfiguredFromEnv: false,
220+
isConfiguredFromRelativePath: true,
221+
setEnvConfig: vi.fn(),
222+
setRelativePathConfig: vi.fn(),
223+
setBackendUrl: vi.fn(),
224+
ping: vi.fn(),
225+
});
226+
227+
// Set query data with empty backendUrl to match the query key
228+
queryClient.setQueryData(
229+
["pipeline-run-metadata", "123", ""],
230+
mockPipelineRun,
231+
);
232+
233+
// act
234+
renderWithProviders(<RunDetails />);
235+
236+
// assert
237+
await waitFor(() => {
238+
expect(screen.getByText("Test Pipeline")).toBeInTheDocument();
239+
expect(
240+
screen.queryByText("Backend not configured"),
241+
).not.toBeInTheDocument();
242+
});
243+
});
244+
});
245+
192246
describe("Inspect Pipeline Button", () => {
193247
test("should render inspect button when pipeline exists", async () => {
194248
// arrange
@@ -278,7 +332,7 @@ describe("<RunDetails/>", () => {
278332
};
279333

280334
queryClient.setQueryData(
281-
["pipeline-run-metadata", "123"],
335+
["pipeline-run-metadata", "123", MOCK_BACKEND_URL],
282336
pipelineRunWithDifferentCreator,
283337
);
284338

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const IOSection = ({ taskSpec, executionId, readOnly }: IOSectionProps) => {
2828
isFetching,
2929
error,
3030
} = useQuery({
31-
queryKey: ["artifacts", executionId],
31+
queryKey: ["artifacts", executionId, backendUrl],
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: 3 additions & 7 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({
118-
queryKey: ["logs", executionId],
117+
const { data, isLoading, error } = useQuery({
118+
queryKey: ["logs", executionId, backendUrl],
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
const useRootExecutionId = (id: string) => {
1515
const { backendUrl } = useBackend();
1616
const { data: rootExecutionId } = useQuery({
17-
queryKey: ["pipeline-run-execution-id", id],
17+
queryKey: ["pipeline-run-execution-id", id, backendUrl],
1818
queryFn: async () => {
1919
const rootExecutionId = await fetchPipelineRun(id, backendUrl)
2020
.then((res) => res.root_execution_id)
@@ -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,8 +41,8 @@ export const usePipelineRunData = (id: string) => {
4141
const rootExecutionId = useRootExecutionId(id);
4242

4343
const { data: executionDetails } = useQuery({
44-
enabled: !!rootExecutionId,
45-
queryKey: ["execution-details", rootExecutionId],
44+
enabled: !!rootExecutionId && !!backendUrl,
45+
queryKey: ["execution-details", rootExecutionId, backendUrl],
4646
queryFn: async () => {
4747
if (!rootExecutionId) {
4848
throw new Error("No root execution id found");
@@ -58,8 +58,8 @@ export const usePipelineRunData = (id: string) => {
5858
error,
5959
isLoading,
6060
} = useQuery({
61-
enabled: !!rootExecutionId && !!executionDetails,
62-
queryKey: ["pipeline-run", rootExecutionId],
61+
enabled: !!rootExecutionId && !!executionDetails && !!backendUrl,
62+
queryKey: ["pipeline-run", rootExecutionId, backendUrl],
6363
queryFn: async () => {
6464
if (!rootExecutionId) {
6565
throw new Error("No root execution id found");

src/hooks/useSubgraphBreadcrumbs.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
"subgraph-breadcrumbs",
36+
rootExecutionId,
37+
subgraphExecutionId,
38+
backendUrl,
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: ["execution-details", currentExecutionId, backendUrl],
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: ["execution-details", parentExecutionId, backendUrl],
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
});

src/providers/ExecutionDataProvider.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "@/services/executionService";
2121
import type { TaskStatusCounts } from "@/types/pipelineRun";
2222

23+
import { useBackend } from "./BackendProvider";
2324
import { useComponentSpec } from "./ComponentSpecProvider";
2425

2526
interface CachedExecutionData {
@@ -84,6 +85,7 @@ const findExecutionIdAtPath = (
8485
rootDetails: GetExecutionInfoResponse | undefined,
8586
cache: Map<string, CachedExecutionData>,
8687
queryClient: ReturnType<typeof useQueryClient>,
88+
backendUrl: string,
8789
): string => {
8890
if (!rootExecutionId) {
8991
return "";
@@ -113,7 +115,7 @@ const findExecutionIdAtPath = (
113115
const cachedQueryData = queryClient.getQueryData<{
114116
details: GetExecutionInfoResponse;
115117
state: GetGraphExecutionStateResponse;
116-
}>(["pipeline-run", nextExecutionId]);
118+
}>(["pipeline-run", nextExecutionId, backendUrl]);
117119

118120
if (cachedQueryData) {
119121
currentDetails = cachedQueryData.details;
@@ -139,6 +141,7 @@ export function ExecutionDataProvider({
139141
subgraphExecutionId?: string;
140142
}>) {
141143
const queryClient = useQueryClient();
144+
const { backendUrl } = useBackend();
142145
const { currentSubgraphPath, navigateToPath } = useComponentSpec();
143146

144147
const executionDataCache = useRef<Map<string, CachedExecutionData>>(
@@ -219,6 +222,7 @@ export function ExecutionDataProvider({
219222
rootDetails,
220223
executionDataCache.current,
221224
queryClient,
225+
backendUrl,
222226
);
223227
}, [
224228
subgraphExecutionId,
@@ -227,6 +231,7 @@ export function ExecutionDataProvider({
227231
rootDetails,
228232
isAtRoot,
229233
queryClient,
234+
backendUrl,
230235
]);
231236

232237
const {

src/services/executionService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export const useFetchPipelineRunMetadata = (runId: string | undefined) => {
4848
const { backendUrl } = useBackend();
4949

5050
return useQuery<PipelineRunResponse>({
51-
queryKey: ["pipeline-run-metadata", runId],
51+
queryKey: ["pipeline-run-metadata", runId, backendUrl],
5252
queryFn: () => fetchPipelineRun(runId!, backendUrl),
53-
enabled: !!runId,
53+
enabled: !!runId && !!backendUrl,
5454
refetchOnWindowFocus: false,
5555
staleTime: TWENTY_FOUR_HOURS_IN_MS,
5656
});
@@ -69,9 +69,9 @@ export const useFetchContainerExecutionState = (
6969
backendUrl: string,
7070
) => {
7171
return useQuery<GetContainerExecutionStateResponse>({
72-
queryKey: ["container-execution-state", executionId],
72+
queryKey: ["container-execution-state", executionId, backendUrl],
7373
queryFn: () => fetchContainerExecutionState(executionId!, backendUrl),
74-
enabled: !!executionId,
74+
enabled: !!executionId && !!backendUrl,
7575
refetchOnWindowFocus: false,
7676
});
7777
};

0 commit comments

Comments
 (0)