{"record":{"id":"1d3fbbf37ce358cc","repo":"lancedb/lancedb","slug":"fragment-ids-not-found-in-dataset-missing-ids","errorCode":null,"errorMessage":"fragment_ids not found in dataset: {missing_ids}","messagePattern":"fragment_ids not found in dataset: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/python/lancedb/query.py","lineNumber":219,"sourceCode":"        raise ValueError(\"fragments and fragment_ids cannot both be set\")\n    if query.fragments is not None:\n        return query.fragments\n    if query.fragment_ids is None:\n        return None\n    if dataset is None:\n        raise ValueError(\"fragment_ids require a Lance dataset\")\n\n    requested = set(query.fragment_ids)\n    fragments = [\n        fragment\n        for fragment in dataset.get_fragments()\n        if fragment.fragment_id in requested\n    ]\n    found = {fragment.fragment_id for fragment in fragments}\n    missing = requested - found\n    if missing:\n        missing_ids = \", \".join(str(fragment_id) for fragment_id in sorted(missing))\n        raise ValueError(f\"fragment_ids not found in dataset: {missing_ids}\")\n    return fragments\n\n\ndef _ensure_lazy_blob_frame(\n    df: \"pd.DataFrame\", schema: pa.Schema, blob_mode: BlobMode\n) -> \"pd.DataFrame\":\n    if blob_mode != \"lazy\" or not schema_has_blob_field(schema) or len(df) == 0:\n        return df\n\n    for field in schema:\n        if not is_blob_like_field(field) or field.name not in df.columns:\n            continue\n        value = df[field.name].iloc[0]\n        if value is not None and not hasattr(value, \"readall\"):\n            raise _unsupported_blob_pandas_error(\n                \"the Lance scanner did not return lazy blob files\"\n            )\n    return df","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/lancedb/lancedb/blob/c7b051aff7039333a3f61b79217246c27676806a/python/python/lancedb/query.py#L201-L237","documentation":"Raised when the fragment_ids supplied to a query include ids that do not exist in the underlying Lance dataset. The library collects the fragments matching the requested ids and raises with the sorted list of missing ids so the caller knows which ones are invalid.","triggerScenarios":"Calling a query builder's fragments(fragment_ids=[...]) with any id not present in the current dataset — e.g. ids from a different table/version, or stale ids after compaction/rewrite changed fragment numbering.","commonSituations":"Reusing fragment ids captured from an older dataset version after data compaction; copying query code between tables; off-by-one id assumptions.","solutions":["Check available ids with [f.fragment_id for f in dataset.get_fragments()] and use only existing ids.","Re-fetch fragment ids from the current table version rather than caching them.","Use a filter or the fragments parameter with resolved fragment objects instead of raw ids."],"exampleFix":"// before\ntbl.fragments(fragment_ids=[5])  # 5 doesn't exist\n// after\nvalid = {f.fragment_id for f in table.to_lance().get_fragments()}\nid = 5\nif id in valid:\n    tbl.fragments(fragment_ids=[id])","handlingStrategy":"validation","validationCode":"valid_ids = {f.fragment_id for f in dataset.get_fragments()}\nbad = set(requested_ids) - valid_ids\nif bad:\n    raise ValueError(f\"unknown fragment ids: {sorted(bad)}\")","typeGuard":"def fragments_exist(dataset, ids) -> bool:\n    return set(ids) <= {f.fragment_id for f in dataset.get_fragments()}","tryCatchPattern":"try:\n    results = builder.fragments(fragment_ids=ids).execute()\nexcept ValueError as e:\n    if \"fragment_ids not found\" in str(e):\n        ids = [i for i in ids if i in {f.fragment_id for f in dataset.get_fragments()}]\n        results = builder.fragments(fragment_ids=ids).execute()","preventionTips":["Re-read fragment ids from the current table version; don't cache across compaction","Validate ids against dataset.get_fragments() right before querying"],"tags":["python","lancedb","fragments"],"backgroundTag":"record-not-found","analyzedSha":"c7b051aff7039333a3f61b79217246c27676806a","analyzedAt":"2026-09-08T23:42:37.579Z","contentChangedAt":"2026-09-08T23:42:37.579Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}