Skip to content

Bug Report: OLS tool ols_get_term_ancestors returns empty terms array despite total_items > 0 #58

@wdeback

Description

@wdeback

Description
The ols_get_term_ancestors tool from OLS (and perhaps others) returns an empty terms array even when total_items indicates ancestors exist. This appears to be caused by incorrect IRI encoding when calling the OLS4 API.

Steps to Reproduce

from tooluniverse import ToolUniverse

tu = ToolUniverse()
tu.load_tools()

result = tu.run({
    'name': 'ols_get_term_ancestors',
    'arguments': {
        'operation': 'get_term_ancestors',
        'term_iri': 'http://purl.obolibrary.org/obo/CL_0000084',
        'ontology': 'cl',
        'size': 50
    }
})

print(result)

Actual Result

{
    'terms': [],  # Empty!
    'total_items': 15,  # But 15 items exist
    'showing': 0,
    'term_iri': 'http://purl.obolibrary.org/obo/CL_0000084',
    'ontology': 'cl',
    'filters': {'include_obsolete': False}
}

Expected Result
The terms array should contain 15 ancestor terms (lymphocyte, leukocyte, cell, etc.)

Root Cause
The OLS4 API requires double URL encoding of the IRI. When calling directly with proper encoding, it works:

from urllib.parse import quote
import requests

term_iri = 'http://purl.obolibrary.org/obo/CL_0000084'
# Double encode the IRI
encoded_iri = quote(quote(term_iri, safe=''), safe='')
url = f'https://www.ebi.ac.uk/ols4/api/ontologies/cl/terms/{encoded_iri}/ancestors'

response = requests.get(url)
data = response.json()
print(len(data['_embedded']['terms']))  # Returns 15

Environment

Workaround
Use direct HTTP calls to the OLS4 API with double-encoded IRIs instead of the ols_get_term_ancestors tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions