Skip to content

Commit 45d611f

Browse files
authored
Allow for missing operation (#1263)
And then default to `overwrite`, see: https://lists.apache.org/thread/h9qmrmlgxh91ol0y2v8olt90b9q6p9xr
1 parent 8f3e6e5 commit 45d611f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pyiceberg/table/snapshots.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import time
20+
import warnings
2021
from collections import defaultdict
2122
from enum import Enum
2223
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Iterable, List, Mapping, Optional
@@ -182,7 +183,10 @@ class Summary(IcebergBaseModel, Mapping[str, str]):
182183
operation: Operation = Field()
183184
_additional_properties: Dict[str, str] = PrivateAttr()
184185

185-
def __init__(self, operation: Operation, **data: Any) -> None:
186+
def __init__(self, operation: Optional[Operation] = None, **data: Any) -> None:
187+
if operation is None:
188+
warnings.warn("Encountered invalid snapshot summary: operation is missing, defaulting to overwrite")
189+
operation = Operation.OVERWRITE
186190
super().__init__(operation=operation, **data)
187191
self._additional_properties = data
188192

tests/table/test_snapshots.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ def test_deserialize_snapshot(snapshot: Snapshot) -> None:
112112
assert actual == snapshot
113113

114114

115+
def test_deserialize_snapshot_without_operation(snapshot: Snapshot) -> None:
116+
payload = """{"snapshot-id": 25, "parent-snapshot-id": 19, "sequence-number": 200, "timestamp-ms": 1602638573590, "manifest-list": "s3:/a/b/c.avro", "summary": {}, "schema-id": 3}"""
117+
with pytest.warns(UserWarning, match="Encountered invalid snapshot summary: operation is missing, defaulting to overwrite"):
118+
actual = Snapshot.model_validate_json(payload)
119+
assert actual.summary.operation == Operation.OVERWRITE
120+
121+
115122
def test_deserialize_snapshot_with_properties(snapshot_with_properties: Snapshot) -> None:
116123
payload = """{"snapshot-id":25,"parent-snapshot-id":19,"sequence-number":200,"timestamp-ms":1602638573590,"manifest-list":"s3:/a/b/c.avro","summary":{"operation":"append","foo":"bar"},"schema-id":3}"""
117124
snapshot = Snapshot.model_validate_json(payload)

0 commit comments

Comments
 (0)