{"record":{"id":"f4144be8449f42ce","repo":"iflytek/astron-agent","slug":"dataset-id-dataset-id-not-visible-to-ragflow-sdk-refusing-to","errorCode":null,"errorMessage":"Dataset id={dataset_id} not visible to RAGFlow SDK; refusing to silently fall back to RAGFLOW_DEFAULT_GROUP to avoid cross-repo upload contamination","messagePattern":"Dataset id=(.+?) not visible to RAGFlow SDK; refusing to silently fall back to RAGFLOW_DEFAULT_GROUP to avoid cross-repo upload contamination","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/ragflow/ragflow_client.py","lineNumber":520,"sourceCode":"      before any dataset lookup.\n\n    Args:\n        dataset_id: Dataset ID; empty string triggers configured fallback.\n        file_content: File content bytes.\n        filename: File name.\n\n    Returns:\n        Upload response containing document ID(s).\n\n    Raises:\n        ValueError: If ``dataset_id`` is provided but not resolvable via SDK,\n            or if the configured fallback cannot resolve a dataset.\n    \"\"\"\n    if dataset_id:\n        rag = get_rag_object()\n        sdk_datasets: List[Any] = rag.list_datasets(id=dataset_id)\n        if not sdk_datasets:\n            raise ValueError(\n                f\"Dataset id={dataset_id} not visible to RAGFlow SDK; \"\n                \"refusing to silently fall back to RAGFLOW_DEFAULT_GROUP \"\n                \"to avoid cross-repo upload contamination\"\n            )\n        return sdk_datasets[0].upload_documents(\n            [{\"displayed_name\": filename, \"blob\": file_content}]\n        )\n\n    return await _upload_via_default_group(file_content=file_content, filename=filename)\n\n\nasync def _resolve_dataset_via_rest(group_name: str, rag: Any) -> Any:\n    \"\"\"Fallback: locate default-group dataset via REST when SDK name lookup fails.\n\n    Kept separate to avoid increasing default-group path complexity.\n    \"\"\"\n    rest_response = await list_datasets(name=group_name)\n    datasets = rest_response.get(\"data\", []) if rest_response else []","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/ragflow/ragflow_client.py#L502-L538","documentation":"upload_document_to_dataset resolves the target dataset through the official RAGFlow SDK (rag.list_datasets(id=...)). If the SDK cannot see the given dataset_id, the function refuses to proceed: it raises ValueError explicitly rather than silently falling back to the RAGFLOW_DEFAULT_GROUP dataset, preventing documents from being uploaded into the wrong (default/shared) dataset — cross-repo contamination.","triggerScenarios":"Calling upload_document_to_dataset with a dataset_id that does not exist in RAGFlow, belongs to another tenant/API key, or was created outside the SDK's visibility, so rag.list_datasets(id=dataset_id) returns an empty list.","commonSituations":"Stale dataset id cached after the dataset was deleted; using a dataset created under a different RAGFlow API token; id copied from a different RAGFlow instance/environment (dev vs prod); tenant/space mismatch where the console passes an internal id that RAGFlow does not know.","solutions":["Verify the dataset_id exists and is visible to the configured RAGFLOW_API_TOKEN via list_datasets (UI or REST call)","Re-create the dataset if it was deleted and use the new id","Check that RAGFLOW_BASE_URL/RAGFLOW_API_TOKEN point to the same RAGFlow instance the dataset belongs to","If intentional, upload without dataset_id so the documented fallback/default-group path applies explicitly"],"exampleFix":"# before\nawait upload_document_to_dataset(stale_dataset_id, filename, blob)  # raises\n# after\ndatasets = await list_datasets()\ntarget = next((d for d in datasets if d['name'] == dataset_name), None)\nif target is None:\n    target = await create_dataset(dataset_name)\nawait upload_document_to_dataset(target['id'], filename, blob)","handlingStrategy":"validation","validationCode":"async def dataset_visible(dataset_id: str) -> bool:\n    rag = get_rag_object()\n    return bool(rag.list_datasets(id=dataset_id))","typeGuard":null,"tryCatchPattern":"try:\n    await upload_document_to_dataset(dataset_id, filename, blob)\nexcept ValueError as e:\n    if 'not visible to RAGFlow SDK' in str(e):\n        logger.error('Dataset %s unknown to RAGFlow; resolve id before upload', dataset_id)\n        raise","preventionTips":["Resolve dataset ids from list_datasets on the same RAGFlow instance/token at upload time","Never cache dataset ids across environments (dev/prod)","Keep RAGFLOW_BASE_URL and RAGFLOW_API_TOKEN pointing at one instance per deployment","Prefer creating the dataset programmatically when the id cannot be verified"],"tags":["ragflow","dataset","validation","data-integrity"],"backgroundTag":"entity-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}