Skip to content
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
9 changes: 8 additions & 1 deletion pyiceberg/table/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from abc import ABC, abstractmethod
from datetime import datetime
from functools import singledispatch
from typing import TYPE_CHECKING, Annotated, Any, Dict, Generic, List, Literal, Optional, Tuple, TypeVar, Union, cast
from typing import TYPE_CHECKING, Annotated, Any, Dict, Generic, List, Literal, Optional, Set, Tuple, TypeVar, Union, cast

from pydantic import Field, field_validator, model_validator

Expand Down Expand Up @@ -756,6 +756,13 @@ def validate(self, base_metadata: Optional[TableMetadata]) -> None:
elif self.snapshot_id is not None:
raise CommitFailedException(f"Requirement failed: branch or tag {self.ref} is missing, expected {self.snapshot_id}")

# override the override method, allowing None to serialize to `null` instead of being omitted.
def model_dump_json(
self, exclude_none: bool = False, exclude: Optional[Set[str]] = None, by_alias: bool = True, **kwargs: Any
) -> str:
# `snapshot-id` is required in json response, even if null
return super().model_dump_json(exclude_none=False)


class AssertLastAssignedFieldId(ValidatableTableRequirement):
"""The table's last assigned column id must match the requirement's `last-assigned-field-id`."""
Expand Down
3 changes: 3 additions & 0 deletions tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ def test_assert_ref_snapshot_id(table_v2: Table) -> None:
):
AssertRefSnapshotId(ref="test", snapshot_id=3055729675574597004).validate(base_metadata)

expected_json = '{"type":"assert-ref-snapshot-id","ref":"main","snapshot-id":null}'
assert AssertRefSnapshotId(ref="main").model_dump_json() == expected_json


def test_assert_last_assigned_field_id(table_v2: Table) -> None:
base_metadata = table_v2.metadata
Expand Down