fix: tolerate null labels/assignees/user in get_issue (#13)
docker / test (pull_request) Successful in 32s
docker / lint (pull_request) Successful in 39s
lint / lint (pull_request) Successful in 34s
test / test (pull_request) Successful in 32s
docker / docker-publish (pull_request) Has been skipped
test / test (push) Successful in 25s
lint / lint (push) Successful in 27s
docker / docker-test (pull_request) Successful in 11s

Gitea may return JSON null for an issue's `labels`, `assignees`, or
`user` fields. `dict.get(key, [])` returns None when the key is present
with a null value (the default is only used for missing keys), so the
list comprehensions raised `'NoneType' object is not iterable` for
otherwise-valid issues. Coalesce with `or []` / `or {}` so empty/null
collections normalize to empty results.

Adds a regression test covering all three null fields.
This commit is contained in:
2026-06-22 10:09:32 +02:00
parent 5f80fc2531
commit 478aee9bed
2 changed files with 31 additions and 3 deletions
+28
View File
@@ -265,6 +265,34 @@ async def test_extended_read_tools_failure_mode() -> None:
await list_commits_tool(ErrorGitea(), {"owner": "acme", "repo": "app"})
@pytest.mark.asyncio
async def test_get_issue_tolerates_null_collections() -> None:
"""Regression for #13: Gitea may return null for labels/assignees/user.
`.get(key, [])` returns None when the key is present with a null value, so
iterating the result raised `'NoneType' object is not iterable`.
"""
class NullFieldsGitea(StubGitea):
async def get_issue(self, owner, repo, index):
return {
"number": index,
"title": "Issue",
"body": "Body",
"state": "open",
"user": None,
"labels": None,
"assignees": None,
}
result = await get_issue_tool(
NullFieldsGitea(), {"owner": "acme", "repo": "app", "issue_number": 1}
)
assert result["author"] == ""
assert result["labels"] == []
assert result["assignees"] == []
@pytest.mark.asyncio
@pytest.mark.parametrize(
"tool,args,expected_key",