kevinjqliu commented on code in PR #2375:
URL: https://github.com/apache/iceberg-python/pull/2375#discussion_r2294828174


##########
tests/test_serializers.py:
##########
@@ -48,3 +50,13 @@ def test_legacy_current_snapshot_id(
     backwards_compatible_static_table = 
StaticTable.from_metadata(metadata_location)
     assert backwards_compatible_static_table.metadata.current_snapshot_id is 
None
     assert backwards_compatible_static_table.metadata == static_table.metadata
+
+
+def test_null_serializer_field() -> None:
+    class ExampleRequest(IcebergBaseModel):
+        requirements: Tuple[TableRequirement, ...]
+
+    request = ExampleRequest(requirements=(AssertRefSnapshotId(ref="main", 
snapshot_id=None),))
+    dumped_json = request.model_dump_json()
+    expected_json = 
"""{"type":"assert-ref-snapshot-id","ref":"main","snapshot-id":null}"""
+    assert expected_json in dumped_json

Review Comment:
   thanks for this test! we also just clarify the spec to allow `null` for 
snapshot-id
   
   https://github.com/apache/iceberg/pull/13902



##########
pyiceberg/table/update/__init__.py:
##########
@@ -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]:

Review Comment:
   nit: rename this to `serialize_model`, which aligns to the [pydantic 
example](https://docs.pydantic.dev/latest/api/functional_serializers/#pydantic.functional_serializers.model_serializer).
 makes this easier to find later 
   ```suggestion
       def serialize_model(self) -> dict[str, Any]:
   ```
   



##########
pyiceberg/table/update/__init__.py:
##########
@@ -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,
+        }

Review Comment:
   nit: is there a way to call super() or the default serializer? we just want 
to explicitly override for `snapshot-id`. 
   
   otherwise, we'd have to remember to change to this function everytime we add 
a new variable



-- 
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]

Reply via email to