Skip to content

fix: dereference list attributes such as CisPhasedBlock.members - #698

Open
syahra712 wants to merge 1 commit into
ga4gh:mainfrom
syahra712:fix/deref-list-references
Open

syahra712 wants to merge 1 commit into
ga4gh:mainfrom
syahra712:fix/deref-list-references

Conversation

@syahra712

Copy link
Copy Markdown
Contributor

vrs_deref fails on any object whose referable attribute is a list, so a CisPhasedBlock can't be round-tripped through vrs_enref / vrs_deref:

from ga4gh.vrs import models, vrs_deref, vrs_enref

store = {}
enreffed = vrs_enref(cis_phased_block, object_store=store)  # members -> ga4gh:VA... ids
vrs_deref(enreffed, object_store=store)
# KeyError: "root='ga4gh:VA.gDM6r-orysWPX-4NuEOx-KaWcyrlTv_t'"

ga4gh_deref copies the object first, which turns the member ids into iriReference models. The list branch then looks each one up with object_store[str(curie)], and str() of a pydantic RootModel is "root='ga4gh:VA...'", not the id. The single-value branch already unwraps with get_pydantic_root. The list branch also assumed every item was a reference, so a list of members that were already inlined raised KeyError too.

The list branch now handles each item like the single-value branch does. A GA4GH identifier is unwrapped with get_pydantic_root and looked up in the store, and an inlined object is passed through as-is. CisPhasedBlock.members, Adjacency.adjoinedSequences and DerivativeMolecule.components all go through this path.

Tests

test_enref_deref_list_attribute in tests/test_vrs.py round-trips the existing cpb_431012 block and checks that already-inlined members pass through. It fails on main with the KeyError above and passes with this change. ruff check and ruff format --check (v0.9.4) are clean. The rest of the suite passes locally, except tests that need a local SeqRepo at /usr/local/share/seqrepo (test_dataproxy, test_vrs_normalize), which I don't have; this change doesn't touch them.

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.

1 participant