Skip to content

fix: serialize enref'd references by digest so ids don't change - #704

Open
arieleven wants to merge 1 commit into
ga4gh:mainfrom
arieleven:fix/enref-digest-of-referenced-objects
Open

arieleven wants to merge 1 commit into
ga4gh:mainfrom
arieleven:fix/enref-digest-of-referenced-objects

Conversation

@arieleven

Copy link
Copy Markdown

vrs_enref gives a different id than ga4gh_identify for an object whose ids aren't set yet. This is the "allele ID is wrong" case from #596:

allele = models.Allele(**input_data)          # no ids yet
ga4gh_identify(allele)                        # ga4gh:VA.K7akyz9P...
vrs_enref(models.Allele(**input_data), {}).id  # ga4gh:VA.UBp6cO0u...

ga4gh_enref replaces location with the location's CURIE as a plain string and then identifies the allele. _recurse_ga4gh_serialize returns plain strings unchanged, so the allele digest is computed over "ga4gh:SL.<digest>" instead of "<digest>". iriReference.ga4gh_serialize already strips the prefix, but a plain string didn't get that treatment.

This change serializes plain GA4GH CURIE strings to their digest too, so the enref'd form and the inlined form give the same id. test_enref2 was passing a precomputed id that came from this bug (VA.LDzK...); it now uses the id ga4gh_identify returns for that allele (VA.0AeP..., the same one shown in #440).

An alternative is to have ga4gh_enref assign iriReference(_id) instead of a string. I went with the serializer because it also covers users who set a reference by hand, and it doesn't change what enreffed.location == "ga4gh:SL..." returns. Happy to switch if you prefer.

Note for downstream stores: any ids that were computed by vrs_enref itself before this fix differ from the ones ga4gh_identify gives.

Tests: new test_enref_without_precomputed_ids fails on main and passes here; full suite passes locally; ruff clean.

Refs #596

ga4gh_enref replaces each referable attribute with the referenced object's CURIE as a plain string, then identifies the parent. _recurse_ga4gh_serialize returned that string unchanged, so the parent's digest was computed over "ga4gh:SL.<digest>" instead of "<digest>". An Allele enref'd without a precomputed id therefore got a different VA id than the same Allele inlined.

Serialize plain GA4GH CURIE strings to their digest, the same way iriReference.ga4gh_serialize already does. test_enref2's fixture carried the id produced by this bug (VA.LDzK...); it now uses the id ga4gh_identify gives for that Allele (VA.0AeP..., as in ga4gh#440).
@arieleven
arieleven requested review from a team as code owners November 26, 2026 06:10

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