From 6ce8d51216f1da161c216f03da24c0d34b9833fe Mon Sep 17 00:00:00 2001 From: Seunghyeon Yang <61305117+1yangsh@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:27:21 +0900 Subject: [PATCH] REST: Map commit_table 404 and 503 responses like Java 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 2ad3684c9a..4f9a6230ae 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -1670,9 +1670,11 @@ def commit_table( _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 3d2b64da92..0d8ca00257 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -61,6 +61,8 @@ ) 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",