This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-4447-f323f289581bfb3f29fd3b4b806f4748045cae5f
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit 535425d2d6abc1bcf3cf3e867f6e266eb108b34b
Author: Anurag-S1ngh <[email protected]>
AuthorDate: Sat Nov 21 07:15:40 2026 +0000

    Core: Check only snapshots an attempt added when detecting a landed commit 
(#4447)
    
    A transaction can register a producer that stages no snapshot, such as a
    delete that matches no files during an overwrite. The landed-attempt check
    required a snapshot for every producer, so it never detected a commit that
    landed and was reported as failed. The retry then raised a validation error
    and deleted the manifests of the snapshot that had already landed.
    
    Check the snapshots the attempt actually added instead.
---
 pyiceberg/table/__init__.py      |  8 +++++---
 tests/table/test_commit_retry.py | 30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py
index 3ea41e3f2..b66c99c74 100644
--- a/pyiceberg/table/__init__.py
+++ b/pyiceberg/table/__init__.py
@@ -79,6 +79,7 @@ from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, 
SortOrder
 from pyiceberg.table.update import (
     AddPartitionSpecUpdate,
     AddSchemaUpdate,
+    AddSnapshotUpdate,
     AddSortOrderUpdate,
     AssertCreate,
     AssertRefSnapshotId,
@@ -1238,7 +1239,7 @@ class Transaction:
         return self._table
 
     def _attempt_landed(self) -> bool:
-        """Refresh the table and return whether a snapshot written by this 
transaction is present.
+        """Refresh the table and return whether the snapshots added by this 
transaction are present.
 
         Raises:
             CommitStateUnknownException: If the table cannot be refreshed, the 
outcome is unknown and
@@ -1251,8 +1252,9 @@ class Transaction:
                 f"Commit failed and the table could not be refreshed to check 
whether it landed: {e}"
             ) from e
 
-        return all(
-            self._table.metadata.snapshot_by_id(producer._snapshot_id) is not 
None for producer in self._snapshot_producers
+        added_snapshot_ids = {update.snapshot.snapshot_id for update in 
self._updates if isinstance(update, AddSnapshotUpdate)}
+        return bool(added_snapshot_ids) and all(
+            self._table.metadata.snapshot_by_id(snapshot_id) is not None for 
snapshot_id in added_snapshot_ids
         )
 
     def _cleanup_uncommitted_manifests(self) -> None:
diff --git a/tests/table/test_commit_retry.py b/tests/table/test_commit_retry.py
index 67653be95..99fcc826f 100644
--- a/tests/table/test_commit_retry.py
+++ b/tests/table/test_commit_retry.py
@@ -1615,6 +1615,36 @@ def 
test_lost_response_on_the_final_retry_keeps_the_landed_snapshot(catalog: Cat
     _assert_single_readable_snapshot(catalog, 
"default.lost_response_final_retry", [{"x": 1}, {"x": 2}, {"x": 3}])
 
 
+def 
test_lost_response_on_overwrite_of_an_empty_table_keeps_the_landed_snapshot(catalog:
 Catalog) -> None:
+    """A producer that stages no snapshot must not make the landed-attempt 
check fail."""
+    catalog.create_namespace("default")
+    table = catalog.create_table("default.lost_response_empty_overwrite", 
schema=_test_schema())
+
+    import pyarrow as pa
+
+    with _commit_outcomes(catalog, "lost"), pytest.warns(UserWarning, 
match="Delete operation did not match any records"):
+        table.overwrite(pa.table({"x": [1, 2, 3]}))
+
+    _assert_single_readable_snapshot(catalog, 
"default.lost_response_empty_overwrite", [{"x": 1}, {"x": 2}, {"x": 3}])
+
+
+def 
test_lost_response_on_empty_table_overwrite_before_any_retry_keeps_the_landed_snapshot(catalog:
 Catalog) -> None:
+    """The landed attempt is detected before the retry budget is consulted."""
+    catalog.create_namespace("default")
+    table = catalog.create_table(
+        "default.lost_response_empty_overwrite_no_retries",
+        schema=_test_schema(),
+        properties={TableProperties.COMMIT_NUM_RETRIES: "0"},
+    )
+
+    import pyarrow as pa
+
+    with _commit_outcomes(catalog, "lost"), pytest.warns(UserWarning, 
match="Delete operation did not match any records"):
+        table.overwrite(pa.table({"x": [1, 2, 3]}))
+
+    _assert_single_readable_snapshot(catalog, 
"default.lost_response_empty_overwrite_no_retries", [{"x": 1}, {"x": 2}, {"x": 
3}])
+
+
 def test_unreadable_commit_outcome_raises_commit_state_unknown(catalog: 
Catalog) -> None:
     """When the table cannot be refreshed, the outcome is unknown and no file 
is deleted."""
     catalog.create_namespace("default")

Reply via email to