Conversation
…g matches In the no-client instance-library path, _instance_lookup.get(name, None) left objects as None when the name had no match, and the subsequent len(objects) raised TypeError. Return an empty list as the default instead, so by_name() correctly returns None. Fixes HumanBrainProject#130
|
AI generated Maintainer review summary for Fairgraph PR #133. Summary reviewed and approved for posting by Keeltrace.
Overall: approve after CI passes; only clean up the PR description. |
|
Thank you for this pull request. I am closing it because the underlying bug was fixed as a side-effect of a PR for a different issue (#138). For future reference, while we are happy to receive AI-assisted contributions, it is important that a human takes the lead, and carefully reviews themselves any parts of the work that were performed by a coding agent. "Fully Automated PRs" that say "Review With Care" just increase our workload. |
|
Super valid. I'm not sure if my bot missed it, but adding something similar to the repo guidelines or a Claude.md will keep bots away. No hard feelings and sorry for any inconvenience |
AI Fully Automated PR - Review With Care
Summary
by_name()on aKGObjectsubclass without a client (the localinstance-library path used by controlled terms) raised
TypeError: object of type 'NoneType' has no len()when the requestedname did not match any instance, instead of returning
None.Reproduction (fairgraph master at time of fix; no KG connection needed):
Root cause
In
fairgraph/kgobject.py, the instance-library branch ofby_name()used
_instance_lookup.get(name, None). When nothing matched,objectswas set to
None, and the followingif len(objects) == 0:checkdereferenced it. The
"contains"branch already initialised an emptylist, so only exact matches were affected.
Fix
One line: default to an empty list —
cls._instance_lookup.get(name, [])— so the existing "no match → return None" path works as documented and
matches the behaviour of
from_id()with an unknown id.Tests
New offline regression test file
test/test_by_name.py(no network orKG credentials required), covering:
None(regression for this issue)match="contains"with no match returnsNoneall=Truereturns allmatchvalue raisesValueErrorVerified that the new test fails with the exact reported
TypeErrorwhen the one-line fix is reverted, and passes with it applied.
Fixes #130
Description corrections (2026-08-25)
Two inaccuracies in the original description above were corrected in place:
fairgraph.openminds.v5...,which does not exist in fairgraph 0.14.0; corrected to the actual
module path (
fairgraph.openminds.controlled_terms). The bug itselfwas reproduced against 0.14.0 as reported.
from_id()" should haveread
from_id()'s sibling lookup API, i.e.get_by_id()was meant —rephrased: the fix makes no-match behaviour consistent rather than
referencing a differently-named accessor. The code change itself is
unchanged by these corrections; only this description was edited.