From e02b1108caa23fd6aad0d9e5297cd67f1d67c6cc Mon Sep 17 00:00:00 2001 From: c-thiel Date: Tue, 14 May 2024 23:04:07 +0200 Subject: [PATCH 1/2] Fix: Table-Exists if Server returns 204 --- pyiceberg/catalog/rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py index 565d809194..d95e0fc56f 100644 --- a/pyiceberg/catalog/rest.py +++ b/pyiceberg/catalog/rest.py @@ -790,4 +790,4 @@ def table_exists(self, identifier: Union[str, Identifier]) -> bool: response = self._session.head( self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier_tuple)) ) - return response.status_code == 200 + return response.status_code in (200, 204) From 1d4b1b1e31e88b402f7c8ca5cdb86bbf2c9510aa Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 19 May 2024 13:03:00 +0200 Subject: [PATCH 2/2] Add test for table exist 204 return code --- tests/catalog/test_rest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py index b8410d6841..7931b8bb0d 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -673,6 +673,16 @@ def test_table_exist_200(rest_mock: Mocker) -> None: assert catalog.table_exists(("fokko", "table")) +def test_table_exist_204(rest_mock: Mocker) -> None: + rest_mock.head( + f"{TEST_URI}v1/namespaces/fokko/tables/table", + status_code=204, + request_headers=TEST_HEADERS, + ) + catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) + assert catalog.table_exists(("fokko", "table")) + + def test_table_exist_500(rest_mock: Mocker) -> None: rest_mock.head( f"{TEST_URI}v1/namespaces/fokko/tables/table",