Skip to content

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

Merged
theferrit32 merged 3 commits into
ga4gh:mainfrom
developer-rpai:fix-489-translator-from-vrs-models
Oct 6, 2026
Merged

theferrit32 merged 3 commits into
ga4gh:mainfrom
developer-rpai:fix-489-translator-from-vrs-models

Conversation

@developer-rpai

Copy link
Copy Markdown
Contributor

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
@theferrit32

Copy link
Copy Markdown
Contributor

Thanks for catching this, @developer-rpai

@theferrit32
theferrit32 merged commit bda2ddd into ga4gh:main Oct 6, 2026
8 checks passed
theferrit32 added a commit that referenced this pull request Oct 6, 2026
The fix landed on main separately (#656, follow-up #668), so remove it and
its tests to keep this branch focused on location bounds validation.
@developer-rpai

Copy link
Copy Markdown
Contributor Author

Thanks for merging this. I am looking to contribute more substantially to vrs-python — is there a larger area (translator coverage, model handling, test infrastructure) where you could use help? Happy to take on something with real scope.

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

2 participants