Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyiceberg/catalog/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,9 +1670,11 @@ def commit_table(
_handle_non_200_response(
exc,
{
404: NoSuchTableError,
409: CommitFailedException,
500: CommitStateUnknownException,
502: CommitStateUnknownException,
503: CommitStateUnknownException,
504: CommitStateUnknownException,
},
)
Expand Down
29 changes: 29 additions & 0 deletions tests/catalog/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
)
from pyiceberg.exceptions import (
AuthorizationExpiredError,
CommitFailedException,
CommitStateUnknownException,
NamespaceAlreadyExistsError,
NamespaceNotEmptyError,
NoSuchIdentifierError,
Expand Down Expand Up @@ -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",
Expand Down
Loading