AllenNeuralDynamics / AllenNeuralDynamics/biodata-models
External API dependency in model definitions
- Lenguaje dominante
- Python
- Estrellas
- 0
- Forks
- 0
- Merge medio
- 2 d 3 h
- PR fusionados (30 d)
- 7
Descripción
It looks like the Emapa service went down today (6/17/26) which caused errors in the metadata-service unit tests
and led to the discovery of a hidden dependency to an external API EMAPA. These API calls are being done silently in the `aind_data_schema_models.mouse_anatomy` module (overriding the `__get_attribute__` method so an external network request is done).
This problem should probably have more visibility though because we should (1) have more observability when external dependencies go down, this shouldn't have been discovered accidentally in a unit test and (2) this design introduces hidden complexity and a hidden dependency in aind-data-schema on an external service.
Here's the error that was found in the tests:
```
src/aind_metadata_service_server/mappers/las2020.py:1279: in get_surgery
targeted_structure = InjectionTargets.INTRAPERITONEAL
/opt/hostedtoolcache/Python/3.10.20/x64/lib/python3.10/site-packages/aind_data_schema_models/mouse_anatomy.py:105: in __getattribute__
emapa_id = get_emapa_id(original_name)
/opt/hostedtoolcache/Python/3.10.20/x64/lib/python3.10/site-packages/aind_data_schema_models/mouse_anatomy.py:71: in get_emapa_id
results = search_emapa_exact_match(class_name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
class_name = 'peritoneal cavity'
def search_emapa_exact_match(class_name):
"""Pull the exact name match from the EMAPA ontology
Parameters
----------
class_name : str
Name of class
Returns
-------
list
Raises
------
Exception
OLS query failed on any status code other than 200
"""
base_url = "https://www.ebi.ac.uk/ols/api/search"
params = {
"q": class_name,
"ontology": "emapa", # Specify the ontology
"type": "class", # Search for classes
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
results = response.json()
# Extract terms with exact label match
exact_matches = [
{
"iri": entry["iri"],
"label": entry["label"],
}
for entry in results.get("response", {}).get("docs", [])
if entry["label"].lower() == class_name.lower()
]
return exact_matches
else:
> raise Exception(f"OLS query failed: {response.status_code}, {response.text}")
E Exception: OLS query failed: 500, {
E "status" : 500,
E "message" : "Raw search query failed"
E }
```
This design pattern is a bit concerning to me since it is unexpected for an attribute lookup on an "enum" to actually be performing an external API call.
When we switch to Dataverse and the biodata registry, then maybe we can consolidate the business logic in one place.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.