aless10 commented on code in PR #8286:
URL: https://github.com/apache/iceberg/pull/8286#discussion_r1291005819


##########
python/pyiceberg/table/metadata.py:
##########
@@ -380,19 +383,14 @@ def new_table_metadata(
 class TableMetadataUtil:
     """Helper class for parsing TableMetadata."""
 
-    # Once this has been resolved, we can simplify this: 
https://github.com/samuelcolvin/pydantic/issues/3846
-    # TableMetadata = Annotated[TableMetadata, Field(alias="format-version", 
discriminator="format-version")]
+    class _MetadataWrapper(IcebergBaseModel):
+        table_metadata: TableMetadata
 
     @staticmethod
-    def parse_obj(data: Dict[str, Any]) -> TableMetadata:
-        if "format-version" not in data:
-            raise ValidationError(f"Missing format-version in TableMetadata: 
{data}")
-
-        format_version = data["format-version"]
-
-        if format_version == 1:
-            return TableMetadataV1(**data)
-        elif format_version == 2:
-            return TableMetadataV2(**data)
-        else:
-            raise ValidationError(f"Unknown format version: {format_version}")
+    def parse_raw(data: str) -> TableMetadata:
+        try:
+            d = f'{{"table_metadata": {data}}}'
+            metadata_wrapper = TableMetadataUtil._MetadataWrapper.parse_raw(d)

Review Comment:
   The discriminator works if it is a field in a model. But it does not work 
per se. We can use it as I did or implement a sort of factory method (as it is 
right now)



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