ragnard commented on code in PR #2866:
URL: https://github.com/apache/iceberg-python/pull/2866#discussion_r2652589630


##########
pyiceberg/table/update/__init__.py:
##########
@@ -181,9 +181,15 @@ class SetStatisticsUpdate(IcebergBaseModel):
 
     @model_validator(mode="before")
     def validate_snapshot_id(cls, data: dict[str, Any]) -> dict[str, Any]:
-        stats = cast(StatisticsFile, data["statistics"])
+        snapshot_id = None
 
-        data["snapshot_id"] = stats.snapshot_id
+        stats = data["statistics"]
+        if isinstance(stats, StatisticsFile):
+            snapshot_id = stats.snapshot_id
+        elif isinstance(stats, dict):
+            snapshot_id = stats.get("snapshot_id")

Review Comment:
   good catch with the `snapsht-id`. I've fixed that, and added a test 
specifically for the snapshot_id handling, creating a model both from a model 
instance, dict and json. the roundtrip testing also exercises the previous bug.



##########
pyiceberg/table/update/__init__.py:
##########
@@ -181,9 +181,15 @@ class SetStatisticsUpdate(IcebergBaseModel):
 
     @model_validator(mode="before")
     def validate_snapshot_id(cls, data: dict[str, Any]) -> dict[str, Any]:
-        stats = cast(StatisticsFile, data["statistics"])
+        snapshot_id = None
 
-        data["snapshot_id"] = stats.snapshot_id
+        stats = data["statistics"]
+        if isinstance(stats, StatisticsFile):
+            snapshot_id = stats.snapshot_id
+        elif isinstance(stats, dict):
+            snapshot_id = stats.get("snapshot_id")

Review Comment:
   good catch with the `snapshot-id`. I've fixed that, and added a test 
specifically for the snapshot_id handling, creating a model both from a model 
instance, dict and json. the roundtrip testing also exercises the previous bug.



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