Skip unsupported ontology prefixes in condition text search#1607
Open
davmlaw wants to merge 2 commits into
Open
Skip unsupported ontology prefixes in condition text search#1607davmlaw wants to merge 2 commits into
davmlaw wants to merge 2 commits into
Conversation
The Monarch Initiative search API can return disease results whose IDs use an ontology prefix that isn't a member of OntologyService (e.g. MPATH, the Mouse Pathology ontology). OntologyIdNormalized.normalize() constructs OntologyService(prefix), which raises ValueError: 'MPATH' is not a valid OntologyService, aborting the whole search. Skip any result whose ID can't be resolved to a supported OntologyService rather than letting it abort the search. OntologyService deliberately enumerates only the ontologies we support, so MPATH is correctly excluded.
…1603 The Monarch /v3/api/search endpoint intermittently returns errors or a non-JSON error page (e.g. a 502 HTML response), which made requests' .json() raise JSONDecodeError and abort the whole condition search (Rollbar item 7269). Catch RequestException/ValueError around the call and treat any failure as no results. Adds regression tests covering the non-JSON, HTTP error and connection error cases alongside the existing unsupported-prefix (MPATH) skip.
8c11af7 to
1d933c3
Compare
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.
What
Make
condition_text_search()(classification/models/condition_text_search.py) resilient to bad results and bad responses from the Monarch Initiative search API. Two related failure modes in the one function are addressed:OntologyServiceare skipped instead of aborting the whole search.Why
1. Unsupported prefix (
ValueError)condition_text_searchbuildsOntologyTerm.get_or_stub(result.get("id"))for every item returned by the Monarch/v3/api/searchendpoint.OntologyIdNormalized.normalize()(ontology/models/models_ontology.py) doesprefix = OntologyService(prefix), which raisesValueError: 'MPATH' is not a valid OntologyServicewhen the prefix isn't a member of theOntologyServiceenum. A single unexpected result (e.g.MPATH, the Mouse Pathology ontology) therefore breaks the entire search. (Rollbar 6250 / 7051.)2. Error / non-JSON response (
JSONDecodeError)The function also called
.json()directly on the response with no guard. The Monarch API is external and intermittently returns errors or a non-JSON error page (e.g. a502HTML page), so.json()raisesJSONDecodeError: Expecting value: line 2 column 1and aborts the search beforenormalize()is ever reached. This is a distinct failure from the MPATH bug — different exception type and line (.json()at line 18 vsget_or_stub/normalizeat line 22). (Rollbar 7269.)The call is now wrapped to
raise_for_status()and catchRequestException/ValueError, returning[](no results) on any API failure.Choice of fix (prefix handling)
Two options were considered:
OntologyService.MPATHto theOntologyServiceenum.Chose (a).
OntologyServicedeliberately enumerates only the ontologies VariantGrid supports for conditions (MONDO, OMIM, HP, HGNC, DOID, ORPHA, MedGen, MeSH); it is not intended to mirror every prefix the external Monarch API might return. MPATH is a mouse pathology ontology, not a human disease/condition ontology, so it should not be added as a supported service. Skipping unknown prefixes keeps the strict enum intact while making the search robust to whatever the external API returns.Tests
Adds
classification/tests/models/test_condition_text_search.pycovering: unsupported-prefix skip (MPATH alongside a valid MONDO term), non-JSON response, HTTP error response (502), and connection error — all mockingrequests.get.Risk
Low. Changes are confined to
condition_text_search; the happy path (valid JSON, supported prefixes) is unaffected, and all failure modes degrade to "no search results" rather than an exception.Addresses #1603
🤖 Generated with Claude Code