fix: return 4XX for malformed input to hgvs/validate - #861
Open
bencap wants to merge 1 commit into
Open
Conversation
The parse step in hgvs_validate ran outside the try/except, so an HGVSParseError on a malformed variant string escaped to the catch-all 500 handler (and fired a Slack alert). A missing "variant" body field raised KeyError with the same outcome. Parse inside the error handler and catch the broad HGVSError so any caller-supplied HGVS failure (unparseable string, inconsistent variant, unknown accession) becomes a 400. Replace the free-form dict body with a typed HgvsValidationRequest model, which makes a missing/mistyped field a 422 and self-documents the request schema.
Coverage Report for CI Build 33196274310Coverage decreased (-0.2%) to 88.843%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions25 previously-covered lines in 4 files lost coverage.
Coverage Stats
💛 - Coveralls |
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
POST /api/v1/hgvs/validatereturned 500 (and fired a Slack alert) for malformed input. This makes caller-input failures return 4XX instead.What changed
hp.parse()previously ran outside thetry/except, so anHGVSParseErroron an unparseable variant string escaped to the catch-all 500 handler. The parse now runs inside the handler, which catches the base classHGVSErrorand returns a 400.variant: dict[str, str]body with a newHgvsValidationRequestview model (variant: str). A missing/mistyped field now returns 422 automatically, and the request schema is self-documenting in OpenAPI.responsesupdated from the 400-only set toVALIDATION_ERROR_RESPONSES(400 + 422).Testing
test_hgvs_validate_unparseable(asserts 400) andtest_hgvs_validate_missing_field(asserts 422).