{"record":{"id":"e354f1f2260a932a","repo":"langgenius/dify","slug":"child-chunk-not-found","errorCode":null,"errorMessage":"Child chunk not found.","messagePattern":"Child chunk not found\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"warning","filePath":"api/controllers/console/datasets/datasets_segments.py","lineNumber":908,"sourceCode":"        DatasetService.check_dataset_model_setting(dataset)\n        # check document\n        document_id_str = str(document_id)\n        document = DocumentService.get_document(dataset_id_str, document_id_str, session=session)\n        if not document:\n            raise NotFound(\"Document not found.\")\n        # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor\n        if not current_user.is_dataset_editor:\n            raise Forbidden()\n        try:\n            DatasetService.check_dataset_permission(dataset, current_user, session)\n        except services.errors.account.NoPermissionError as e:\n            raise Forbidden(str(e))\n        segment_id_str = str(segment_id)\n        segment_ref, _ = _get_segment_for_document(session, dataset, document, segment_id_str)\n        child_chunk_id_str = str(child_chunk_id)\n        child_chunk = SegmentService.get_child_chunk_by_segment_ref(child_chunk_id_str, segment_ref, session=session)\n        if not child_chunk:\n            raise NotFound(\"Child chunk not found.\")\n        try:\n            SegmentService.delete_child_chunk(child_chunk, dataset, session)\n        except ChildChunkDeleteIndexServiceError as e:\n            raise ChildChunkDeleteIndexError(str(e))\n        return \"\", 204\n\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @cloud_edition_billing_resource_check(\"vector_space\")\n    @cloud_edition_billing_rate_limit_check(\"knowledge\")\n    @console_ns.doc(params=SegmentDocParams.DATASET_DOCUMENT_CHILD_CHUNK)\n    @console_ns.expect(console_ns.models[ChildChunkUpdatePayload.__name__])\n    @console_ns.response(200, \"Child chunk updated successfully\", console_ns.models[ChildChunkDetailResponse.__name__])\n    @with_current_user\n    @with_current_tenant_id\n    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)\n    @with_session","sourceCodeStart":890,"sourceCodeEnd":926,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/datasets_segments.py#L890-L926","documentation":"Raised in the DELETE child-chunk handler after segment and child-chunk resolution when SegmentService.get_child_chunk_by_segment_ref returns None for the given child_chunk_id under the resolved segment_ref. The target child chunk does not exist or was already deleted, so the controller returns NotFound (HTTP 404).","triggerScenarios":"DELETE .../child_chunks/{child_chunk_id} where the child chunk was already removed, belongs to a different segment, or the id is wrong.","commonSituations":"Double-delete from a UI that did not refresh; concurrent delete by another user; id mismatch after re-segmentation.","solutions":["Treat a 404 on delete as success if the goal was removal (the chunk is already gone).","Refresh the child-chunk list to confirm current ids before deleting.","Guard against concurrent deletes with a UI lock or re-fetch before the destructive call."],"exampleFix":"// before\nDELETE .../child_chunks/{already_deleted_id}  -> 404\n// after\nGET .../child_chunks  -> list current ids\nif id present: DELETE .../child_chunks/{id}\nelse: no-op (already removed)","handlingStrategy":"try-catch","validationCode":"async function deleteChildChunkIfPresent(ids) {\n  const list = await fetch(`/console/api/datasets/${ids.datasetId}/documents/${ids.documentId}/segments/${ids.segmentId}/child_chunks`).then(r => r.json());\n  if (!(list.data || []).some(c => c.id === ids.childChunkId)) return {skipped: true};\n  return fetch(`/console/api/datasets/${ids.datasetId}/documents/${ids.documentId}/segments/${ids.segmentId}/child_chunks/${ids.childChunkId}`, {method: 'DELETE'});\n}","typeGuard":"const isValidChildChunkId = (id) => typeof id === 'string' && /^[0-9a-fA-F-]{36}$/.test(id);","tryCatchPattern":"try { await deleteChildChunk(ids); }\ncatch (e) { if (e.status === 404 && /Child chunk not found/.test(e.message)) return; /* idempotent success */ throw e; }","preventionTips":["Treat 'Child chunk not found' on DELETE as success (idempotent).","Refresh the child-chunk list before destructive actions to avoid double deletes.","Guard concurrent deletes with a re-fetch."],"tags":["datasets","child-chunk","delete","not-found","idempotency"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}