Fokko commented on code in PR #200: URL: https://github.com/apache/iceberg-python/pull/200#discussion_r1421948214
########## pyiceberg/table/__init__.py: ########## @@ -540,18 +540,38 @@ def update_table_metadata(base_metadata: TableMetadata, updates: Tuple[TableUpda class TableRequirement(IcebergBaseModel): type: str + @abstractmethod + def validate(self, base_metadata: TableMetadata) -> None: + """Validate the requirement against the base metadata. + + Args: + base_metadata: The base metadata to be validated against. + + Raises: + CommitFailedException: When the requirement is not met. + """ + ... + class AssertCreate(TableRequirement): """The table must not already exist; used for create transactions.""" type: Literal["assert-create"] = Field(default="assert-create") + def validate(self, base_metadata: Optional[TableMetadata]) -> None: Review Comment: Should we update the signature of the parent class as well? ########## pyiceberg/table/__init__.py: ########## @@ -564,41 +584,84 @@ class AssertRefSnapshotId(TableRequirement): ref: str snapshot_id: Optional[int] = Field(default=None, alias="snapshot-id") + def validate(self, base_metadata: TableMetadata) -> None: + snapshot_ref = base_metadata.refs.get(self.ref) + if snapshot_ref is not None: Review Comment: Calling in the Walrus operator: ```suggestion if snapshot_ref := base_metadata.refs.get(self.ref): ``` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org