Skip to content

Feat/v2.8.0 reliability#54

Open
nebay-abraha wants to merge 5 commits into
masterfrom
feat/v2.8.0-reliability
Open

Feat/v2.8.0 reliability#54
nebay-abraha wants to merge 5 commits into
masterfrom
feat/v2.8.0-reliability

Conversation

@nebay-abraha

@nebay-abraha nebay-abraha commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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

  • Introduce a public exception hierarchy exported from the package root.
  • Improve HTTP response error handling, including malformed JSON, non-JSON error responses, and preserving response context in ApiError.
  • Add configurable HTTP sessions with retry, timeout, and backoff support.
  • Route upload and download operations through shared request helpers for consistent retry and error handling.
  • Stream downloads instead of buffering entire files in memory.
  • Expose the installed package version via __version__.
  • Deprecate the legacy serr logging helper in favor of the library logger.
  • Expand unit test coverage for retries, exception mapping, uploads/downloads, streaming, and version handling.

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

  • Added 23 new unit tests covering:
    • Exception hierarchy and error mapping
    • Retry policy and timeout propagation
    • Session configuration
    • Upload/download helpers
    • Streaming downloads
    • Version resolution
  • Full test suite passes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread rspace_client/inv/inv.py Outdated
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 thread rspace_client/exceptions.py Outdated
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.
@nebay-abraha nebay-abraha marked this pull request as draft July 13, 2026 13:13
@nebay-abraha nebay-abraha marked this pull request as ready for review July 14, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants