Skip to content

KGObject.from_id() raises TypeError instead of returning None for a non-existent id (untyped path) #115

Description

@apdavison

When from_id() is called on the base KGObject class (i.e. the type isn't known up front) with an id that doesn't exist in the KG, it raises TypeError: 'NoneType' object is not subscriptable instead of returning None.

In fairgraph/kgobject.py, the untyped branch of from_id() does:

data = client.instance_from_full_uri(uri, use_cache=use_cache, release_status=release_status)
type_ = data["@type"]

instance_from_full_uri() returns None for a missing/inaccessible instance, so data["@type"] fails.

The typed path (from_uri) handles this correctly with if data is None: return None, and the from_id docstring states that a return of None means the object doesn't exist or isn't accessible — so the untyped path should behave the same.

Repro:

from fairgraph import KGClient, KGObject
client = KGClient(host="core.kg.ebrains.eu")
KGObject.from_id("https://kg.ebrains.eu/api/instances/<nonexistent-uuid>", client, release_status="any")
# -> TypeError: 'NoneType' object is not subscriptable

Suggested fix: guard data is None (return None) in the untyped branch, mirroring from_uri. Seen with fairgraph 0.13.6.

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