kevinjqliu commented on code in PR #2343:
URL: https://github.com/apache/iceberg-python/pull/2343#discussion_r2284071031
##########
pyiceberg/table/update/__init__.py:
##########
@@ -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:
+ return super().model_dump_json(
+ exclude_none=exclude_none,
exclude=self._exclude_private_properties(exclude), by_alias=by_alias, **kwargs
+ )
Review Comment:
nit: i think we can simply this to
```
def model_dump_json(self) -> str:
# `snapshot-id` is required in json response, even if null
return super().model_dump_json(exclude_none=False)
```
##########
tests/table/test_init.py:
##########
@@ -1039,6 +1039,11 @@ 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_json = AssertRefSnapshotId(ref="main").model_dump_json()
+ print(assert_json)
+ assert assert_json == expected_json
Review Comment:
simplify and remove the print statement
```suggestion
expected_json =
'{"type":"assert-ref-snapshot-id","ref":"main","snapshot-id":null}'
assert AssertRefSnapshotId(ref="main").model_dump_json() == expected_json
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]