Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for missing operation #1263

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pyiceberg/table/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from __future__ import annotations

import time
import warnings
from collections import defaultdict
from enum import Enum
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Iterable, List, Mapping, Optional
Expand Down Expand Up @@ -182,7 +183,10 @@ class Summary(IcebergBaseModel, Mapping[str, str]):
operation: Operation = Field()
_additional_properties: Dict[str, str] = PrivateAttr()

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

Expand Down
7 changes: 7 additions & 0 deletions tests/table/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def test_deserialize_snapshot(snapshot: Snapshot) -> None:
assert actual == snapshot


def test_deserialize_snapshot_without_operation(snapshot: Snapshot) -> None:
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}"""
with pytest.warns(UserWarning, match="Encountered invalid snapshot summary: operation is missing, defaulting to overwrite"):
actual = Snapshot.model_validate_json(payload)
assert actual.summary.operation == Operation.OVERWRITE


def test_deserialize_snapshot_with_properties(snapshot_with_properties: Snapshot) -> None:
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}"""
snapshot = Snapshot.model_validate_json(payload)
Expand Down