-
Notifications
You must be signed in to change notification settings - Fork 498
Add serializer for AssertRefSnapshotId allowing null json value #2375
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
Changes from 3 commits
7d1c461
fcdd773
14000dc
c799fc9
caac6c5
84bf133
8343358
7cd78c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,9 @@ | |
| 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, Set, Tuple, TypeVar, Union, cast | ||
| from typing import TYPE_CHECKING, Annotated, Any, Dict, Generic, List, Literal, Optional, Tuple, TypeVar, Union, cast | ||
|
|
||
| from pydantic import Field, field_validator, model_validator | ||
| from pydantic import Field, field_validator, model_validator, model_serializer | ||
|
|
||
| from pyiceberg.exceptions import CommitFailedException | ||
| from pyiceberg.partitioning import PARTITION_FIELD_ID_START, PartitionSpec | ||
|
|
@@ -727,6 +727,14 @@ class AssertRefSnapshotId(ValidatableTableRequirement): | |
| ref: str = Field(...) | ||
| snapshot_id: Optional[int] = Field(default=None, alias="snapshot-id") | ||
|
|
||
| @model_serializer | ||
| def ser_model(self) -> dict[str, Any]: | ||
| return { | ||
| "type": self.type, | ||
| "ref": self.ref, | ||
| "snapshot-id": self.snapshot_id, | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is there a way to call super() or the default serializer? we just want to explicitly override for otherwise, we'd have to remember to change to this function everytime we add a new variable
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! Added the |
||
|
|
||
| def validate(self, base_metadata: Optional[TableMetadata]) -> None: | ||
| if base_metadata is None: | ||
| raise CommitFailedException("Requirement failed: current table metadata is missing") | ||
|
|
@@ -745,13 +753,6 @@ 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`.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.