Fokko commented on code in PR #4303:
URL: https://github.com/apache/iceberg-python/pull/4303#discussion_r4543209935
##########
pyiceberg/table/update/__init__.py:
##########
@@ -763,7 +763,16 @@ def update_table_metadata(
if enforce_validation:
return TableMetadataUtil.parse_obj(new_metadata.model_dump())
else:
- return new_metadata.model_copy(deep=True)
+ return _copy_containers(new_metadata)
+
+
+def _copy_containers(metadata: TableMetadata) -> TableMetadata:
+ """Copy the list and dict fields of the metadata and share the frozen
models they hold.
+
+ The frozen config cannot prevent a list append or a dict assignment on a
field, so copying the
+ containers keeps the base metadata isolated without deep-copying the whole
table history.
+ """
+ return metadata.model_copy(update={name: value.copy() for name, value in
metadata if isinstance(value, (list, dict))})
Review Comment:
Seems like a reasonable change, since the object can be pretty big. But I
think we don't need the helper since it is only called from one place.
```suggestion
return metadata.model_copy(update={name: value.copy() for name,
value in metadata if isinstance(value, (list, dict))})
```
--
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]