{"record":{"id":"33679e9d3511e044","repo":"pola-rs/polars","slug":"iceberg-snapshot-id-not-found-self-snapshot-id","errorCode":null,"errorMessage":"iceberg snapshot ID not found: {self.snapshot_id}","messagePattern":"iceberg snapshot ID not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_dataset.py","lineNumber":235,"sourceCode":"    fast_deletion_count: bool\n    use_pyiceberg_filter: bool\n\n    #\n    # PythonDatasetProvider interface functions\n    #\n\n    def schema(self) -> pa.schema:\n        \"\"\"Fetch the schema of the table.\"\"\"\n        from pyiceberg.io.pyarrow import schema_to_pyarrow\n\n        if self.snapshot_id is None:\n            return self.table.arrow_schema()\n\n        snapshot = self.table.get().snapshot_by_id(self.snapshot_id)\n\n        if snapshot is None:\n            msg = f\"iceberg snapshot ID not found: {self.snapshot_id}\"\n            raise ValueError(msg)\n\n        schema_id = snapshot.schema_id\n\n        if schema_id is None:\n            msg = (\n                f\"IcebergScanResolver: requested snapshot {self.snapshot_id} \"\n                \"did not contain a schema ID\"\n            )\n            raise ValueError(msg)\n        return schema_to_pyarrow(self.table.get().schemas()[schema_id])\n\n    def to_dataset_scan(\n        self,\n        *,\n        existing_resolved_version_key: str | None = None,\n        limit: int | None = None,\n        projection: list[str] | None = None,\n        filter_columns: list[str] | None = None,","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_dataset.py#L217-L253","documentation":"IcebergScanResolver.schema() was asked to resolve the table schema against a specific snapshot ID, but pyiceberg's snapshot_by_id() returned None: the table's metadata contains no snapshot with that ID. polars raises ValueError rather than silently falling back to the current schema.","triggerScenarios":"Constructing IcebergScanResolver with a snapshot_id (e.g. from a previously cached scan version key) that no longer exists in the table metadata, then calling .schema().","commonSituations":"Scanning a table at an old snapshot ID after the table was expired (expire_snapshots) or rewritten; passing a snapshot ID from a different table; a typo'd or integer-vs-string coerced snapshot ID.","solutions":["List valid snapshot IDs via table.metadata.snapshots (or table.snapshots()) and use one that exists.","Omit the snapshot_id / use the current snapshot instead of a pinned one.","If the snapshot was expired, restore it from the table's history or re-resolve the scan against the current snapshot."],"exampleFix":"// before\ndf = pl.scan_iceberg(tbl, snapshot_id=1234567890).collect()  # expired snapshot\n\n// after\nvalid = {s.snapshot_id for s in tbl.snapshots()}\nsid = 1234567890 if 1234567890 in valid else None  # fall back to current\n df = pl.scan_iceberg(tbl, snapshot_id=sid).collect()","handlingStrategy":"validation","validationCode":"valid_ids = {s.snapshot_id for s in tbl.snapshots()}\nif snapshot_id is not None and snapshot_id not in valid_ids:\n    snapshot_id = None  # or pick latest\npl.scan_iceberg(uri, snapshot_id=snapshot_id)","typeGuard":"def snapshot_exists(tbl, snapshot_id: int) -> bool:\n    return snapshot_id is not None and tbl.snapshot_by_id(snapshot_id) is not None","tryCatchPattern":"try:\n    df = pl.scan_iceberg(uri, snapshot_id=sid).collect()\nexcept ValueError as e:\n    if \"snapshot ID not found\" in str(e):\n        df = pl.scan_iceberg(uri).collect()  # current snapshot\n    else:\n        raise","preventionTips":["Refresh cached snapshot IDs from table metadata before each scan.","Keep snapshot retention long enough for consumers that pin snapshot IDs.","Validate snapshot IDs against tbl.snapshots() before pinning."],"tags":["iceberg","snapshot","resource-not-found","python"],"backgroundTag":"record-not-found","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}