From f9f5626ca48d56d875444504e4745d2b059965fc Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 13 Feb 2024 16:50:59 +1300 Subject: [PATCH] community[patch]: Fix github search issues and PRs PaginatedList has no len() error (#16806) **Description:** Bugfix: Langchain_community's GitHub Api wrapper throws a TypeError when searching for issues and/or PRs (the `search_issues_and_prs` method). This is because PyGithub's PageinatedList type does not support the len() method. See https://github.com/PyGithub/PyGithub/issues/1476 ![image](https://github.com/langchain-ai/langchain/assets/8849021/57390b11-ed41-4f48-ba50-f3028610789c) **Dependencies:** None **Twitter handle**: @ChrisKeoghNZ I haven't registered an issue as it would take me longer to fill the template out than to make the fix, but I'm happy to if that's deemed essential. I've added a simple integration test to cover this as there were no existing unit tests and it was going to be tricky to set them up. Co-authored-by: Chris Keogh --- libs/community/langchain_community/utilities/github.py | 2 +- .../tests/integration_tests/utilities/test_github.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/utilities/github.py b/libs/community/langchain_community/utilities/github.py index 6c2950dcc9..410fdb494b 100644 --- a/libs/community/langchain_community/utilities/github.py +++ b/libs/community/langchain_community/utilities/github.py @@ -735,7 +735,7 @@ class GitHubAPIWrapper(BaseModel): str: A string containing the first 5 issues and pull requests """ search_result = self.github.search_issues(query, repo=self.github_repository) - max_items = min(5, len(search_result)) + max_items = min(5, search_result.totalCount) results = [f"Top {max_items} results:"] for issue in search_result[:max_items]: results.append( diff --git a/libs/community/tests/integration_tests/utilities/test_github.py b/libs/community/tests/integration_tests/utilities/test_github.py index 6e21a8a9c1..77b87ec64f 100644 --- a/libs/community/tests/integration_tests/utilities/test_github.py +++ b/libs/community/tests/integration_tests/utilities/test_github.py @@ -19,3 +19,9 @@ def test_get_open_issues(api_client: GitHubAPIWrapper) -> None: """Basic test to fetch issues""" issues = api_client.get_issues() assert len(issues) != 0 + + +def test_search_issues_and_prs(api_client: GitHubAPIWrapper) -> None: + """Basic test to search issues and PRs""" + results = api_client.search_issues_and_prs("is:pr is:merged") + assert len(results) != 0