jiakai-li opened a new issue, #1505:
URL: https://github.com/apache/iceberg-python/issues/1505

   ### Apache Iceberg version
   
   0.8.1 (latest release)
   
   ### Please describe the bug 🐞
   
   While working on the issue of #1493 I noticed urrently when running below 
code, the field `field_should_not_exist` will be added to the table.
   
   ```python
   from pyiceberg.catalog.sql import SqlCatalog
   from pyiceberg.schema import Schema
   from pyiceberg.types import IntegerType, NestedField, StringType
   
   WAREHOUSE_PATH = "/workspaces/iceberg-python/warehouse"
   catalog = SqlCatalog(
       "default",
       uri=f"sqlite:///{WAREHOUSE_PATH}/pyiceberg_catalog.db", 
warehouse=f"file://{WAREHOUSE_PATH}",
   )
   catalog.create_namespace_if_not_exists("default")
   
   try:
       catalog.drop_table("default.test")
   except:
       pass
   
   schema = Schema(
       NestedField(1, "field1", StringType(), required=False)
   )
   
   table = catalog.create_table("default.test", schema)
   
   with table.update_schema() as update:
       update.add_column("field_should_not_exist", IntegerType())
       raise Exception("Error!")
   ```
   
   The behaviour is a bit confuse to me. Due to an error is raised within the 
context manager, I would expect the transaction to be aborted. But seems commit 
is currently the only option to exit the context manager:
   
   ```python
   class UpdateTableMetadata(ABC, Generic[U]):
       _transaction: Transaction
   
       def __init__(self, transaction: Transaction) -> None:
           self._transaction = transaction
   
       @abstractmethod
       def _commit(self) -> UpdatesAndRequirements: ...
   
       def commit(self) -> None:
           self._transaction._apply(*self._commit())
   
       def __exit__(self, _: Any, value: Any, traceback: Any) -> None:
           """Close and commit the change."""
           self.commit()  # <----- we currently ignore the exc_type
   
       def __enter__(self) -> U:
           """Update the table."""
           return self  # type: ignore
   ```
   
   ### Willingness to contribute
   
   - [X] I can contribute a fix for this bug independently
   - [ ] I would be willing to contribute a fix for this bug with guidance from 
the Iceberg community
   - [ ] I cannot contribute a fix for this bug at this time


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

Reply via email to