Repository navigation
fix(wqp): report WQP's reason for a rejected query - #478
Draft
thodson-usgs wants to merge 4 commits into
Draft
thodson-usgs wants to merge 4 commits into
thodson-usgs wants to merge 4 commits into
Conversation
WQP states why it rejected a query, and the raised error left it out.
The legacy interface sends the reason in a `Warning` header with an
empty body (`299 WQP "The value of lat=nan is not between -90 and
90."`), and WQX3 sends it as a text/plain body. A new `detail_from`
reader adds it to the message, so `what_sites(lat=float("nan"), ...)`
now says what to fix in place of a bare `HTTP 400 Bad Request`.
`_query_with_retry` passes `detail_from` to `_get_with_retry`, which
already accepted it.
Two values WQP could not read are also handled in `_check_kwargs`:
- A `bBox` given as a list of four numbers was joined with semicolons
on the legacy interface (HTTP 400, "not a valid bounding box") and
sent as four repeated keys on WQX3 (HTTP 500). It is now joined
with commas, the form both interfaces read (checked live).
- `zip=True` became `zip=yes` after DOI-USGS#477, and WQP then returns a zip
archive that the CSV parser fails on with a ParserError. A `zip`
that requests an archive now raises `NotImplementedError` with the
remedy, as `mimeType="geojson"` already does.
Also: the `query()` docstring states how scalars and `None` are sent,
and `lat`, `long` and `within` are documented as a string or number.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `detail_from` docstring said "a truthy result is appended"; it now says the function returns the reason or `None`, and a non-empty reason is added after the status. The `bBox` and `zip` docstrings, comments, test docstrings, the error message and NEWS now say that WQP accepts only the comma form, and that this package cannot parse a zip archive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WQX3 returns a zip archive for `zip=YES` and `zip=Yes` as well as `zip=yes` (checked live), so the refusal now compares the value without regard to case. WQP sends its reason as `299 WQP "text"`, with a `"` in the text replaced by `'` and backslashes left as sent. Undoing RFC quoted-pair escapes removed a backslash the caller had sent, and a reason that ended in one did not match at all. A Warning from another agent, such as a proxy, was also reported as WQP's reason and hid the WQX3 body. The pattern now matches only `299 WQP "..."` and takes the text as sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
These seem like pretty low risk edge cases. I don't see a single wqp function where |
Collaborator
Author
|
Yeah, fair enough. |
Collaborator
|
Is there a public catalog of these server-side error messages? That would be interesting to see, but not required for this pass-through. |
ehinman
approved these changes
Dec 2, 2026
This branch has not been deployed
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
WQP states why it rejects a query, and the raised error left that reason out. The wqp adapter now passes a
detail_fromfunction that reads the reason from the response. It also sends abBoxlist in the one form WQP accepts, and raises forzip=True, whose zip archive this package cannot parse.Where WQP puts the reason (checked live on 2026-12-01):
/data/Warning: 299 WQP "<reason>", with a"in the reason sent as'and a backslash sent as is/wqx3/text/plainbodyInvalid request (id '...'): <reason>This follows the code review of #473. Its boolean finding is already fixed by #477. Two other findings are left out on purpose:
lat=nanon both interfaces, and this PR adds WQP's reason to that error. ANoneornaninside a list is ignored by both interfaces, and the other values in the list still filter the results.Evidence
Live WQP, before this change:
bBox=-89.5;43.0;-89.3;43.2(a list joined by the legacy serializer)not a valid bounding boxbBoxsent as four repeated keysbBox=-89.5,43.0,-89.3,43.2on either interfacezip=yesapplication/zip, thenread_code_csvraisesParserError: Expected 2 fields in line 5, saw 3zip=YESorzip=Yesapplication/zip(legacy rejects both with a 400)Tests in
tests/wqp_test.py:what_sites(siteid=...)against a mocked legacy 400 raisesHTTP 400 Bad Request (URL: ...).After: it raises
HTTP 400 Bad Request: The value of bBox=... is not a valid bounding box. (URL: ...).what_sites(legacy=..., bBox=[-92.8, 44.2, -88.9, 46.0])sendsbBox=-92.8;44.2;-88.9;46.0(legacy) or fourbBoxkeys (WQX3).After: both send
bBox=-92.8,44.2,-88.9,46.0._wqp_error_detailhas unit cases for one and twoWarningheaders, a backslash as WQP sends it, a warn-date, a proxy'sWarningbeside a WQX3 body (the body's reason is used), a WQX3 body with LF and CRLF endings, an empty body and an HTML body. Each case returns the reason orNone. The function also returns the expected text for the threeWarningheaders and the one WQX3 body that WQP sent during the live checks.The offline suite (1,682 tests), coverage, ruff,
mypy --strict, lint-imports, xenon and complexipy pass.Merge Danger
Door: two-way
Blast Radius: wqp
zip=True, andzip="yes"in any case, now raiseNotImplementedErrorbefore the request is sent. Since fix(wqp): send a boolean as yes or no #477 they returned a zip archive that failed to parse. Before Send numeric and boolean query values instead of dropping them #473,zip=Truewas dropped._query_with_retrytakes a new keyword-onlydetail_from. NLDI andutils.querydo not pass it, so their behavior does not change.🤖 Generated with Claude Code