Skip to content

fix: resolve VRS model class via getattr in from-VRS translation - #656

Open
developer-rpai wants to merge 1 commit into
ga4gh:mainfrom
developer-rpai:fix-489-translator-from-vrs-models
Open

developer-rpai wants to merge 1 commit into
ga4gh:mainfrom
developer-rpai:fix-489-translator-from-vrs-models

Conversation

@developer-rpai

Copy link
Copy Markdown

Bug

Translating FROM VRS (a dict VRS object) via _Translator._from_vrs crashed with TypeError: 'module' object is not subscriptable. The code subscripted models (the ga4gh.vrs.models module) with var["type"].

Root cause

In src/ga4gh/vrs/extras/translator.py, _from_vrs did model = 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

  • Reproduced the crash on pristine upstream main before the fix: translate_from(vrs_dict, fmt="vrs") raised TypeError at translator.py line 170.
  • Added regression test test_from_vrs_dict in tests/extras/test_allele_translator.py: a valid VRS dict now translates to an Allele without TypeError; unknown types, non dict input, and missing type all return None.
  • After the fix the new test passes, and the valid dict round trips to a models.Allele.

What I could not verify

  • The full existing translator test suite cannot run green in this sandbox: 20 tests in test_allele_translator.py and 7 in test_cnv_translator.py fail identically before and after this change because they need live network access to uta.biocommons.org and a local seqrepo REST server, which are unavailable here. No new failures were introduced by this change.
  • CI on this PR has not been observed; I am not claiming it is green.

Closes #489

_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
@developer-rpai
developer-rpai requested review from a team as code owners September 24, 2026 06:08

This branch has not been deployed

No deployments
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.

Input type issues in using Translator to translate from VRS

1 participant