mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-25 12:34:41 +08:00
fix: Indefinitely loading KB page for errors (#12295)
* fix indefinitely loading KB page * [autofix.ci] apply automated fixes * retry for 5XX error * [autofix.ci] apply automated fixes * improved testcase name --------- Co-authored-by: Olayinka Adelakun <olayinkaadelakun@mac.war.can.ibm.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com> Co-authored-by: Olayinka Adelakun <olayinkaadelakun@Olayinkas-MacBook-Pro.local>
This commit is contained in:
@ -552,6 +552,7 @@ async def get_knowledge_base_chunks(
|
||||
search: Annotated[str, Query(description="Filter chunks whose text contains this substring")] = "",
|
||||
) -> PaginatedChunkResponse:
|
||||
"""Get chunks from a specific knowledge base with pagination."""
|
||||
kb_path: Path | None = None
|
||||
try:
|
||||
kb_path = _resolve_kb_path(kb_name, current_user)
|
||||
|
||||
@ -631,7 +632,8 @@ async def get_knowledge_base_chunks(
|
||||
finally:
|
||||
client = None
|
||||
chroma = None
|
||||
KBStorageHelper.release_chroma_resources(kb_path)
|
||||
if kb_path is not None:
|
||||
KBStorageHelper.release_chroma_resources(kb_path)
|
||||
|
||||
|
||||
@router.delete("/{kb_name}", status_code=HTTPStatus.OK)
|
||||
|
||||
@ -694,6 +694,20 @@ class TestKnowledgeBaseAPI:
|
||||
assert data["page"] == 2
|
||||
mock_collection.get.assert_called_with(include=["documents", "metadatas"], limit=10, offset=10)
|
||||
|
||||
@patch("langflow.api.v1.knowledge_bases.KBStorageHelper.get_root_path")
|
||||
async def test_get_chunks_non_existent_kb_returns_404(
|
||||
self,
|
||||
mock_root,
|
||||
client: AsyncClient,
|
||||
logged_in_headers,
|
||||
tmp_path,
|
||||
):
|
||||
mock_root.return_value = tmp_path
|
||||
|
||||
response = await client.get("api/v1/knowledge_bases/MissingKB/chunks", headers=logged_in_headers)
|
||||
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
class TestPerformIngestionTask:
|
||||
"""Tests for the internal KBIngestionHelper.perform_ingestion background task."""
|
||||
|
||||
@ -63,6 +63,13 @@ export const useGetKnowledgeBaseChunks: useQueryFunctionType<
|
||||
getChunksFn,
|
||||
{
|
||||
enabled: !!params?.kb_name,
|
||||
retry: (failureCount, error: any) => {
|
||||
const status = error?.response?.status;
|
||||
if (typeof status === "number") {
|
||||
return status >= 500 && failureCount < 3;
|
||||
}
|
||||
return failureCount < 3;
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
...options,
|
||||
},
|
||||
|
||||
@ -93,6 +93,19 @@ describe("SourceChunksPage", () => {
|
||||
render(<SourceChunksPage />);
|
||||
expect(screen.getByText("Failed to load chunks")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows error message on 4xx errors", () => {
|
||||
mockGetChunks.mockReturnValue({
|
||||
isLoading: false,
|
||||
isError: true,
|
||||
data: undefined,
|
||||
error: { response: { status: 404 } },
|
||||
});
|
||||
|
||||
render(<SourceChunksPage />);
|
||||
|
||||
expect(screen.getByText("Failed to load chunks")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Empty state", () => {
|
||||
|
||||
Reference in New Issue
Block a user