Closed korikuzma closed 1 month ago
Wanted to post original message from slack on 2/22
I was having an issue with our FastAPI endpoints only returning the minimal information needed to create a digest. We define the response_model as a Pydantic model.
For example, it would return:
{
"variation": {
"location": "t-3DrWALhgLdXHsupI-e-M00aL3HgK3y",
"state": {
"sequence": "E",
"type": "LiteralSequenceExpression"
},
"type": "Allele"
}
}
rather than the expected
{
"variation": {
"id": "ga4gh:VA.j4XnsLZcdzDIYa5pvvXM7t1wn9OITr0L",
"type": "Allele",
"digest": "j4XnsLZcdzDIYa5pvvXM7t1wn9OITr0L",
"location": {
"id": "ga4gh:SL.t-3DrWALhgLdXHsupI-e-M00aL3HgK3y",
"type": "SequenceLocation",
"digest": "t-3DrWALhgLdXHsupI-e-M00aL3HgK3y",
"sequenceReference": {
"type": "SequenceReference",
"refgetAccession": "SQ.cQvw4UsHHRRlogxbWCB8W-mKD4AraM9y"
},
"start": 599,
"end": 600
},
"state": {
"type": "LiteralSequenceExpression",
"sequence": "E"
}
}
}
I think this is because FastAPI sets the mode to json in this line: https://github.com/tiangolo/fastapi/blob/master/fastapi/encoders.py#L225
The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
A work around for this is to remove the response_model field from our FastAPI endpoints and return model.model_dump(exclude_none=True)
directly.
Closed by #571.
542 removed the models. we should look at a solution for adding these back. we may want to consider looking to see if there's an alternate way to compute the digests in vrs-python