{"record":{"id":"da0dcce2ce69aacb","repo":"pola-rs/polars","slug":"icebergscanresolver-requested-snapshot-self-snapshot-id-did","errorCode":null,"errorMessage":"IcebergScanResolver: requested snapshot {self.snapshot_id} did not contain a schema ID","messagePattern":"IcebergScanResolver: requested snapshot (.+?) did not contain a schema ID","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_dataset.py","lineNumber":244,"sourceCode":"        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,\n        pyarrow_predicate: str | None = None,\n    ) -> tuple[LazyFrame, str] | None:\n        \"\"\"Construct a LazyFrame scan.\"\"\"\n        if (\n            scan_data := self._to_dataset_scan_impl(\n                existing_resolved_version_key=existing_resolved_version_key,\n                limit=limit,\n                projection=projection,\n                filter_columns=filter_columns,","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_dataset.py#L226-L262","documentation":"The requested snapshot exists but its metadata carries schema_id = None, so IcebergScanResolver.schema() cannot map the snapshot to a schema in the table's schemas() map. polars raises ValueError because a schema is mandatory to build the Arrow schema for the scan.","triggerScenarios":"Calling IcebergScanResolver.schema() on a snapshot whose Snapshot.schema_id is None — typically snapshots produced by writers that did not record a schema-id field in snapshot metadata.","commonSituations":"Tables written by older or non-standard Iceberg writers; snapshots imported from legacy formats; hand-built/patched table metadata in testing.","solutions":["Use a different snapshot (one that has a schema_id) or omit snapshot_id to use the current schema.","Rewrite the table metadata (e.g. with pyiceberg's rewrite or a rewrite_data_files/migrate operation) so snapshots carry a schema_id.","As a workaround, read the table's current schema via table.schema() and construct the scan without snapshot pinning."],"exampleFix":"// before\nresolver.schema()  # snapshot has schema_id == None\n\n// after\nsnapshot = tbl.snapshot_by_id(resolver.snapshot_id)\nif snapshot.schema_id is None:\n    snapshot = tbl.current_snapshot()  # or another snapshot with a schema_id","handlingStrategy":"try-catch","validationCode":"snapshot = tbl.snapshot_by_id(snapshot_id)\nif snapshot is not None and snapshot.schema_id is None:\n    snapshot_id = None  # fall back to current schema","typeGuard":"def has_schema_id(tbl, snapshot_id: int | None) -> bool:\n    if snapshot_id is None:\n        return True\n    snap = tbl.snapshot_by_id(snapshot_id)\n    return snap is not None and snap.schema_id is not None","tryCatchPattern":"try:\n    resolver.schema()\nexcept ValueError as e:\n    if \"did not contain a schema ID\" in str(e):\n        resolver = IcebergScanResolver(..., snapshot_id=None)\n        return resolver.schema()\n    raise","preventionTips":["Avoid pinning snapshots on tables written by legacy writers that omit schema-id.","Check snapshot.schema_id before resolving a pinned snapshot.","Prefer scanning the current snapshot unless time-travel is required."],"tags":["iceberg","snapshot","schema","metadata"],"backgroundTag":"missing-required-argument","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"}