You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "dingo4dev (via GitHub)" <gi...@apache.org> on 2025/08/29 05:21:24 UTC
[PR] Add `close()` method to RestCatalog [iceberg-python]
dingo4dev opened a new pull request, #2403:
URL: https://github.com/apache/iceberg-python/pull/2403
<!--
Thanks for opening a pull request!
-->
<!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
Part of #2399
# Rationale for this change
This PR introducs the implementation of `close()` method to the `RestCatalog`.
And add corresponding test case which following the test pattern in #2390
## Are these changes tested?
Yes
## Are there any user-facing changes?
<!-- In the case of user-facing changes, please add the changelog label. -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add `close()` method to RestCatalog [iceberg-python]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2403:
URL: https://github.com/apache/iceberg-python/pull/2403#discussion_r2309169273
##########
tests/catalog/test_rest.py:
##########
@@ -1845,3 +1845,76 @@ def test_rest_catalog_with_google_credentials_path(
assert len(history) == 1
actual_headers = history[0].headers
assert actual_headers["Authorization"] == expected_auth_header
+
+
+class TestRestCatalogClose:
+ """Tests RestCatalog close functionality"""
+
+ EXPECTED_ADAPTERS = 2
+ EXPECTED_ADAPTERS_SIGV4 = 3
+
+ def test_catalog_close(self, rest_mock: Mocker) -> None:
+ rest_mock.get(
+ f"{TEST_URI}v1/config",
+ json={"defaults": {}, "overrides": {}},
+ status_code=200,
+ )
+
+ catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
+ catalog.close()
+ # Verify session still exists after close the session pooled connections
+ assert hasattr(catalog, "_session")
+ assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+ # Second close should not raise any exception
+ catalog.close()
+
+ def test_rest_catalog_close_sigv4(self, rest_mock: Mocker) -> None:
+ catalog = None
Review Comment:
The `catalog = None` initialization is unnecessary since the variable is immediately assigned in the context manager. This line can be removed.
```suggestion
```
##########
tests/catalog/test_rest.py:
##########
@@ -1845,3 +1845,76 @@ def test_rest_catalog_with_google_credentials_path(
assert len(history) == 1
actual_headers = history[0].headers
assert actual_headers["Authorization"] == expected_auth_header
+
+
+class TestRestCatalogClose:
+ """Tests RestCatalog close functionality"""
+
+ EXPECTED_ADAPTERS = 2
+ EXPECTED_ADAPTERS_SIGV4 = 3
+
+ def test_catalog_close(self, rest_mock: Mocker) -> None:
+ rest_mock.get(
+ f"{TEST_URI}v1/config",
+ json={"defaults": {}, "overrides": {}},
+ status_code=200,
+ )
+
+ catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
+ catalog.close()
+ # Verify session still exists after close the session pooled connections
+ assert hasattr(catalog, "_session")
+ assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+ # Second close should not raise any exception
+ catalog.close()
+
+ def test_rest_catalog_close_sigv4(self, rest_mock: Mocker) -> None:
+ catalog = None
+ rest_mock.get(
+ f"{TEST_URI}v1/config",
+ json={"defaults": {}, "overrides": {}},
+ status_code=200,
+ )
+
+ catalog = RestCatalog("rest", **{"uri": TEST_URI, "token": TEST_TOKEN, "rest.sigv4-enabled": "true"})
+ catalog.close()
+ assert hasattr(catalog, "_session")
+ assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS_SIGV4
+
+ def test_rest_catalog_context_manager_with_exception(self, rest_mock: Mocker) -> None:
+ """Test RestCatalog context manager properly closes with exceptions."""
+ catalog = None
Review Comment:
The `catalog = None` initialization is unnecessary since the variable is immediately assigned in the context manager. This line can be removed.
```suggestion
```
##########
tests/catalog/test_rest.py:
##########
@@ -1845,3 +1845,76 @@ def test_rest_catalog_with_google_credentials_path(
assert len(history) == 1
actual_headers = history[0].headers
assert actual_headers["Authorization"] == expected_auth_header
+
+
+class TestRestCatalogClose:
+ """Tests RestCatalog close functionality"""
+
+ EXPECTED_ADAPTERS = 2
+ EXPECTED_ADAPTERS_SIGV4 = 3
+
+ def test_catalog_close(self, rest_mock: Mocker) -> None:
+ rest_mock.get(
+ f"{TEST_URI}v1/config",
+ json={"defaults": {}, "overrides": {}},
+ status_code=200,
+ )
+
+ catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
+ catalog.close()
+ # Verify session still exists after close the session pooled connections
+ assert hasattr(catalog, "_session")
+ assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+ # Second close should not raise any exception
+ catalog.close()
+
+ def test_rest_catalog_close_sigv4(self, rest_mock: Mocker) -> None:
+ catalog = None
+ rest_mock.get(
+ f"{TEST_URI}v1/config",
+ json={"defaults": {}, "overrides": {}},
+ status_code=200,
+ )
+
+ catalog = RestCatalog("rest", **{"uri": TEST_URI, "token": TEST_TOKEN, "rest.sigv4-enabled": "true"})
+ catalog.close()
+ assert hasattr(catalog, "_session")
+ assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS_SIGV4
+
+ def test_rest_catalog_context_manager_with_exception(self, rest_mock: Mocker) -> None:
+ """Test RestCatalog context manager properly closes with exceptions."""
+ catalog = None
+ rest_mock.get(
+ f"{TEST_URI}v1/config",
+ json={"defaults": {}, "overrides": {}},
+ status_code=200,
+ )
+
+ try:
+ with RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN) as cat:
+ catalog = cat
+ raise ValueError("Test exception")
+ except ValueError:
+ pass
+
+ assert catalog is not None and hasattr(catalog, "_session")
+ assert len(catalog._session.adapters) == self.EXPECTED_ADAPTERS
+
+ def test_rest_catalog_context_manager_with_exception_sigv4(self, rest_mock: Mocker) -> None:
+ """Test RestCatalog context manager properly closes with exceptions."""
+ catalog = None
Review Comment:
The `catalog = None` initialization is unnecessary since the variable is immediately assigned in the context manager. This line can be removed.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Add `close()` method to RestCatalog [iceberg-python]
Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu merged PR #2403:
URL: https://github.com/apache/iceberg-python/pull/2403
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org