utils.query: surface unhandled 4xx/5xx and stop mutating caller's payload#253
Draft
thodson-usgs wants to merge 1 commit intoDOI-USGS:mainfrom
Draft
utils.query: surface unhandled 4xx/5xx and stop mutating caller's payload#253thodson-usgs wants to merge 1 commit intoDOI-USGS:mainfrom
thodson-usgs wants to merge 1 commit intoDOI-USGS:mainfrom
Conversation
… payload Two related correctness fixes to the shared HTTP wrapper used by every module in the package. * The function only formatted explicit messages for 400, 404, 414, and 500/502/503. Any other status (401, 403, 405, 408, 429, 501, 504, …) fell through and the response was returned as if it had succeeded — callers parsed an HTML error page as RDB or CSV. Add a ``raise_for_status()`` after the explicit branches so every non-success surfaces, while keeping the friendlier messages for the codes we already format. * The body did ``for key, value in payload.items(): payload[key] = to_str(...)``, mutating the caller's dict. List values came back replaced with their stringified joins, breaking any caller that re-used the dict. Build a fresh ``params`` dict in a comprehension and leave the input alone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Two related correctness fixes to the shared HTTP wrapper used by every module in the package.
Unhandled 4xx/5xx silently passed through. `query` only formatted explicit messages for 400, 404, 414, and 500/502/503 — every other status (401, 403, 405, 408, 429, 501, 504, …) fell through and the response was returned as if it had succeeded. Callers then parsed an HTML error page as RDB or CSV and reported confusing downstream errors. Adds a `response.raise_for_status()` call after the explicit branches so every non-success surfaces, while keeping the friendlier messages for the codes we already format.
`query` mutated the caller's payload dict. The body did `for key, value in payload.items(): payload[key] = to_str(...)` in place, so list values came back replaced with their stringified joins after the call returned. Build a fresh `params` dict in a comprehension and leave the input alone.
Test plan