Skip to content

by_name() raises TypeError instead of returning None when nothing matches #130

Description

@apdavison

KGObject.by_name() raises TypeError rather than returning None when called without a client and no instance matches:

>>> from fairgraph.openminds.v4.controlled_terms import Species
>>> Species.by_name("definitely not a species")
TypeError: object of type 'NoneType' has no len()

The instance-library branch assigns the miss as None (fairgraph/kgobject.py:946):

if match == "equals":
    objects = cls._instance_lookup.get(name, None)

and line 954 then calls len(objects).

The equivalent openMINDS method returns None for the same input, so this is a regression introduced by fairgraph's override, and it affects only the no-client path.

It arises more often than "no such term" suggests, because the instance-library lookup is exact and case-sensitive: any difference in case is a miss, so Species.by_name("mus musculus") raises while Species.by_name("Mus musculus") returns the term.

Same shape as #115 — a None sentinel used without a guard. The fix is to treat a miss as an empty result; a regression test needs no KG connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions