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

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


The following commit(s) were added to refs/heads/main by this push:
     new f91ce5314 REST: Map commit_table 404 and 503 responses like Java 
(#4465)
f91ce5314 is described below

commit f91ce53145fa6780961c23092fa75f090ae853f2
Author: Seunghyeon Yang <[email protected]>
AuthorDate: Sat Nov 21 19:48:55 2026 +0000

    REST: Map commit_table 404 and 503 responses like Java (#4465)
    
    commit_table documents NoSuchTableError for a missing table, but a 404
    was not mapped and surfaced as a generic RESTError. A 503 raised
    ServiceUnavailableError, while Java's CommitErrorHandler treats 500,
    502, 503 and 504 as CommitStateUnknownException, since the server may
    have applied the commit.
---
 pyiceberg/catalog/rest/__init__.py |  2 ++
 tests/catalog/test_rest.py         | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/pyiceberg/catalog/rest/__init__.py 
b/pyiceberg/catalog/rest/__init__.py
index 2ad3684c9..4f9a6230a 100644
--- a/pyiceberg/catalog/rest/__init__.py
+++ b/pyiceberg/catalog/rest/__init__.py
@@ -1670,9 +1670,11 @@ class RestCatalog(Catalog):
             _handle_non_200_response(
                 exc,
                 {
+                    404: NoSuchTableError,
                     409: CommitFailedException,
                     500: CommitStateUnknownException,
                     502: CommitStateUnknownException,
+                    503: CommitStateUnknownException,
                     504: CommitStateUnknownException,
                 },
             )
diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py
index 3d2b64da9..0d8ca0025 100644
--- a/tests/catalog/test_rest.py
+++ b/tests/catalog/test_rest.py
@@ -61,6 +61,8 @@ from pyiceberg.catalog.rest import (
 )
 from pyiceberg.exceptions import (
     AuthorizationExpiredError,
+    CommitFailedException,
+    CommitStateUnknownException,
     NamespaceAlreadyExistsError,
     NamespaceNotEmptyError,
     NoSuchIdentifierError,
@@ -2977,6 +2979,33 @@ def test_table_identifier_in_commit_table_request(
     )
 
 
+def test_commit_table_error_mapping(rest_mock: Mocker) -> None:
+    catalog = RestCatalog("catalog_name", uri=TEST_URI, token=TEST_TOKEN)
+    table = Table(
+        identifier=("namespace", "table_name"),
+        metadata=None,  # type: ignore
+        metadata_location="s3://some_bucket/metadata.json",
+        io=None,  # type: ignore
+        catalog=catalog,
+    )
+    for status_code, error_type, expected_exception in [
+        (404, "NoSuchTableException", NoSuchTableError),
+        (409, "CommitFailedException", CommitFailedException),
+        (500, "ServiceFailureException", CommitStateUnknownException),
+        (502, "BadGatewayException", CommitStateUnknownException),
+        (503, "ServiceUnavailableException", CommitStateUnknownException),
+        (504, "GatewayTimeoutException", CommitStateUnknownException),
+    ]:
+        rest_mock.post(
+            url=f"{TEST_URI}v1/namespaces/namespace/tables/table_name",
+            json={"error": {"message": "Commit error", "type": error_type, 
"code": status_code}},
+            status_code=status_code,
+            request_headers=TEST_HEADERS,
+        )
+        with pytest.raises(expected_exception, match="Commit error"):
+            catalog.commit_table(table, (), ())
+
+
 def test_register_view_200(rest_mock: Mocker, example_view_metadata_rest_json: 
dict[str, Any]) -> None:
     rest_mock.head(
         f"{TEST_URI}v1/namespaces/default/tables/registered_view",

Reply via email to