Skip to content

fix: return 4XX for malformed input to hgvs/validate - #861

Open
bencap wants to merge 1 commit into
release-2026.3.0from
fix/hgvs-validate-parse-error-500
Open

fix: return 4XX for malformed input to hgvs/validate#861
bencap wants to merge 1 commit into
release-2026.3.0from
fix/hgvs-validate-parse-error-500

Conversation

@bencap

@bencap bencap commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

POST /api/v1/hgvs/validate returned 500 (and fired a Slack alert) for malformed input. This makes caller-input failures return 4XX instead.

What changed

  • Parse inside the error handler. hp.parse() previously ran outside the try/except, so an HGVSParseError on an unparseable variant string escaped to the catch-all 500 handler. The parse now runs inside the handler, which catches the base class HGVSError and returns a 400.
  • Typed request body. Replaced the free-form variant: dict[str, str] body with a new HgvsValidationRequest view model (variant: str). A missing/mistyped field now returns 422 automatically, and the request schema is self-documenting in OpenAPI.
  • Docs. Endpoint responses updated from the 400-only set to VALIDATION_ERROR_RESPONSES (400 + 422).

Testing

  • Added test_hgvs_validate_unparseable (asserts 400) and test_hgvs_validate_missing_field (asserts 422).

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.
@bencap bencap linked an issue Aug 28, 2026 that may be closed by this pull request
@bencap
bencap requested a review from jstone-dev August 28, 2026 18:11
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33196274310

Coverage decreased (-0.2%) to 88.843%

Details

  • Coverage decreased (-0.2%) from the base build.
  • Patch coverage: 10 of 10 lines across 2 files are fully covered (100%).
  • 25 coverage regressions across 4 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

25 previously-covered lines in 4 files lost coverage.

File Lines Losing Coverage Coverage
src/mavedb/lib/utils.py 11 28.13%
src/mavedb/lib/clinvar/utils.py 6 90.59%
src/mavedb/worker/jobs/external_services/clinvar.py 5 94.95%
src/mavedb/lib/vep.py 3 87.76%

Coverage Stats

Coverage Status
Relevant Lines: 15614
Covered Lines: 13872
Line Coverage: 88.84%
Coverage Strength: 0.89 hits per line

💛 - Coveralls

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.

POST /api/v1/hgvs/validate returns 500 for malformed input

2 participants