Repository navigation
Conversation
Add a requests.Session-based client to maap.utils.requests_utils with retries (429/5xx + connection errors, idempotent methods only unless opted in), default timeouts, request-time auth injection with an auth=False opt-out, and token redaction in debug logs. make_request and make_dps_request now delegate to it and support PUT/DELETE. No other callers are migrated yet. Refs #137 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rp9gSo9Fw6M7DUFhWnNPaU
| adapter = HTTPAdapter(max_retries=_build_retry(methods)) | ||
| session = requests.Session() | ||
| session.mount('https://', adapter) | ||
| session.mount('http://', adapter) |
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.
Github Issue: #137 (item 1 of 5)
Description
maap-py makes ~35 direct
requests.*calls with no retries, no timeouts and duplicated auth-header construction. This is the first step of consolidating them: add the shared client only, with no callers migrated yet (items 2-5 in #137 follow as separate PRs).Overview of work done
In
maap/utils/requests_utils.py:get_session()returns a shared, lazily createdrequests.Session(connection pooling) with a retryingHTTPAdapter: retries connection errors and 429/500/502/503/504 with exponential backoff, honoursRetry-After, and returns the last response rather than raisingRetryError.retry_post=True, which uses a separate session, so job submission can't be duplicated.request()helper: default(10, 60)timeout, auth headers (token/Authorization,MAAP_PGT) read from config on every call rather than snapshotted,auth=Falseto avoid sending MAAP credentials to third-party hosts, extraheadersmerged without mutating the caller's dict.token,Authorizationandproxy-ticket(previously the full headers were logged).make_request/make_dps_requestnow delegate torequest(). As a consequence, existingdps_job.pycallers gain retries and a timeout, and PUT/DELETE no longer raiseNotImplementedError.Overview of verification done
New
test/test_requests_utils.py(17 tests) runs against a local HTTP server, sinceresponsesmocks at the adapter level and would bypass urllib3 retries. It covers retry on 503/502/429, PUT/DELETE retry, no POST retry by default and opt-in, exhausted retries returning the last response, no retry on 404, default and overridden timeout, per-call token refresh, Bearer vstokenheader,auth=False, header non-mutation, token redaction in logs, andmake_requestfor all methods.test_requests_utils.pypasses and flake8 is clean. The remaining suite shows the same 20 failures and 16 errors with and without this change (verified on the base branch); they need outbound network access, which was blocked in my environment.Overview of integration done
None yet. Nothing outside
dps_job.pyuses this module so far, so a deployment check is best done once callers are migrated in the follow-up PRs.PR checklist:
🤖 Generated with Claude Code
https://claude.ai/code/session_01Rp9gSo9Fw6M7DUFhWnNPaU
Generated by Claude Code