fix: resolve VRS model class via getattr in from-VRS translation - #656
Open
developer-rpai wants to merge 1 commit into
Open
developer-rpai wants to merge 1 commit into
developer-rpai wants to merge 1 commit into
Conversation
_from_vrs subscripted the ga4gh.vrs.models module with var["type"],
raising TypeError ('module' object is not subscriptable) for any VRS dict
input. Resolve the model class with getattr(models, var["type"], None)
and return None gracefully for unknown types, preserving the original
intent of the KeyError guard.
Closes ga4gh#489
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.
Bug
Translating FROM VRS (a dict VRS object) via
_Translator._from_vrscrashed withTypeError: 'module' object is not subscriptable. The code subscriptedmodels(thega4gh.vrs.modelsmodule) withvar["type"].Root cause
In
src/ga4gh/vrs/extras/translator.py,_from_vrsdidmodel = models[var["type"]]. Modules are not subscriptable, so any VRS dict input crashed. The surrounding try/except KeyError was meant to return None for unknown types, but the TypeError was never caught.Fix
Resolve the model class with
getattr(models, var["type"], None)and return None gracefully when the type is unknown, preserving the original intent. Scope is the crash only; the broader translator redesign discussed in the thread is left to maintainers.Verification
translate_from(vrs_dict, fmt="vrs")raised TypeError at translator.py line 170.test_from_vrs_dictintests/extras/test_allele_translator.py: a valid VRS dict now translates to anAllelewithout TypeError; unknown types, non dict input, and missing type all return None.What I could not verify
Closes #489