Feat/v2.8.0 reliability#54
Open
nebay-abraha wants to merge 5 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves HTTP reliability across the client by centralizing request execution through a shared requests.Session, adding consistent timeout propagation, introducing a retry policy, and hardening error/exception handling (including binary downloads and multipart uploads).
Changes:
- Introduce a shared session with retries, timeouts, streaming downloads, multipart helper, and improved exception mapping in
ClientBase. - Refactor ELN/Inventory upload and binary endpoints to use the shared HTTP helpers.
- Add focused unit tests for retry policy, session config, timeout propagation, download streaming, and exception behavior; update existing filesystem tests to patch session methods.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| rspace_client/tests/inv_attachment_fs_test.py | Updates mocks/expectations to patch requests.Session.* and validate timeout/streaming behavior. |
| rspace_client/tests/http_layer_test.py | Adds new unit tests covering session, retry policy, timeout propagation, exception mapping, multipart, downloads, streaming. |
| rspace_client/tests/exceptions_test.py | Adds unit tests for exception hierarchy and _handle_response robustness. |
| rspace_client/tests/eln_fs_test.py | Updates mocks/expectations to patch requests.Session.* and validate timeout/streaming behavior. |
| rspace_client/inv/inv.py | Routes inventory uploads/icons/barcode and a connectivity check through the shared HTTP helpers/session. |
| rspace_client/exceptions.py | Introduces module-level exception hierarchy for stable public API and deprecation path. |
| rspace_client/eln/eln.py | Routes multipart uploads/imports through the shared multipart helper. |
| rspace_client/client_base.py | Adds session construction, retry policy, timeout propagation, multipart and raw-response helpers, streaming downloads, and improved error handling. |
| rspace_client/init.py | Exposes __version__ and re-exports exception types from the package root. |
| pyproject.toml | Adds responses as a dev dependency for HTTP mocking in tests. |
| .gitignore | Ignores .claude/ directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -123,14 +222,16 @@ | |||
| headers = self._get_headers(content_type) | |||
Comment on lines
+257
to
+260
| url = endpoint | ||
| if not endpoint.startswith(self._get_api_url()): | ||
| url = self._get_api_url() + endpoint | ||
| try: |
Comment on lines
+98
to
+105
| def test_default_timeout_passed_to_get(self): | ||
| client = ELNClient(RSPACE_URL, "fake-api-key") | ||
| with mock.patch.object( | ||
| client._session, "get", return_value=make_response(200, json_body={}) | ||
| ) as mocked_get: | ||
| client.retrieve_api_results("/status") | ||
| self.assertEqual(DEFAULT_TIMEOUT, mocked_get.call_args.kwargs["timeout"]) | ||
|
|
Comment on lines
+106
to
+113
| def test_constructor_timeout_passed_to_non_get(self): | ||
| client = ELNClient(RSPACE_URL, "fake-api-key", timeout=(5, 120)) | ||
| with mock.patch.object( | ||
| client._session, "request", return_value=make_response(200, json_body={}) | ||
| ) as mocked_request: | ||
| client.retrieve_api_results("/forms", request_type="POST") | ||
| self.assertEqual((5, 120), mocked_request.call_args.kwargs["timeout"]) | ||
|
|
Comment on lines
+7
to
+9
| Before version 2.8.0 these lived as nested classes on ClientBase | ||
| (e.g. ``ClientBase.ApiError``). Those names remain as aliases of the classes | ||
| defined here and will be removed in 3.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves the reliability of the ResearchSpace Python client by strengthening error handling, introducing configurable HTTP retries/timeouts, and standardizing request handling across the library.
Changes
ApiError.__version__.serrlogging helper in favor of the library logger.Why
These changes make the client more resilient to transient network failures, provide a consistent error model across all request paths, reduce memory usage during downloads, and improve the public API for consumers.
Testing