From 669f444c5db82c0660ed0ebae4912488c86ab8c8 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 2 Jan 2026 20:07:28 +0000 Subject: [PATCH] fix: resolve deprecation warnings for pythonjsonlogger, PyGithub, and get_matching_events - Update pythonjsonlogger.jsonlogger.JsonFormatter to pythonjsonlogger.json.JsonFormatter - Update Github(token) to Github(auth=Auth.Token(token)) for remaining instances - Replace deprecated get_matching_events with search_events using EventFilter Co-authored-by: openhands --- .../integrations/github/data_collector.py | 4 +- .../integrations/github/github_manager.py | 6 +- .../integrations/github/github_solvability.py | 4 +- enterprise/integrations/github/github_view.py | 4 +- enterprise/integrations/utils.py | 58 +++++++++++++------ openhands/core/logger.py | 4 +- 6 files changed, 50 insertions(+), 30 deletions(-) diff --git a/enterprise/integrations/github/data_collector.py b/enterprise/integrations/github/data_collector.py index 2d1f4b1b18..c6a9b4d6ae 100644 --- a/enterprise/integrations/github/data_collector.py +++ b/enterprise/integrations/github/data_collector.py @@ -143,7 +143,7 @@ class GitHubDataCollector: try: installation_token = self._get_installation_access_token(installation_id) - with Github(installation_token) as github_client: + with Github(auth=Auth.Token(installation_token)) as github_client: repo = github_client.get_repo(repo_name) issue = repo.get_issue(issue_number) comments = [] @@ -237,7 +237,7 @@ class GitHubDataCollector: def _get_pr_commits(self, installation_id: str, repo_name: str, pr_number: int): commits = [] installation_token = self._get_installation_access_token(installation_id) - with Github(installation_token) as github_client: + with Github(auth=Auth.Token(installation_token)) as github_client: repo = github_client.get_repo(repo_name) pr = repo.get_pull(pr_number) diff --git a/enterprise/integrations/github/github_manager.py b/enterprise/integrations/github/github_manager.py index 8b5d9fc542..0d6d9d655f 100644 --- a/enterprise/integrations/github/github_manager.py +++ b/enterprise/integrations/github/github_manager.py @@ -77,7 +77,7 @@ class GithubManager(Manager): reaction: The reaction to add (e.g. "eyes", "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket") installation_token: GitHub installation access token for API access """ - with Github(installation_token) as github_client: + with Github(auth=Auth.Token(installation_token)) as github_client: repo = github_client.get_repo(github_view.full_repo_name) # Add reaction based on view type if isinstance(github_view, GithubInlinePRComment): @@ -199,7 +199,7 @@ class GithubManager(Manager): outgoing_message = message.message if isinstance(github_view, GithubInlinePRComment): - with Github(installation_token) as github_client: + with Github(auth=Auth.Token(installation_token)) as github_client: repo = github_client.get_repo(github_view.full_repo_name) pr = repo.get_pull(github_view.issue_number) pr.create_review_comment_reply( @@ -211,7 +211,7 @@ class GithubManager(Manager): or isinstance(github_view, GithubIssueComment) or isinstance(github_view, GithubIssue) ): - with Github(installation_token) as github_client: + with Github(auth=Auth.Token(installation_token)) as github_client: repo = github_client.get_repo(github_view.full_repo_name) issue = repo.get_issue(number=github_view.issue_number) issue.create_comment(outgoing_message) diff --git a/enterprise/integrations/github/github_solvability.py b/enterprise/integrations/github/github_solvability.py index cdc6af05ec..3f2bdc17b5 100644 --- a/enterprise/integrations/github/github_solvability.py +++ b/enterprise/integrations/github/github_solvability.py @@ -1,7 +1,7 @@ import asyncio import time -from github import Github +from github import Auth, Github from integrations.github.github_view import ( GithubInlinePRComment, GithubIssueComment, @@ -47,7 +47,7 @@ def fetch_github_issue_context( context_parts.append(f'Title: {github_view.title}') context_parts.append(f'Description:\n{github_view.description}') - with Github(user_token) as github_client: + with Github(auth=Auth.Token(user_token)) as github_client: repo = github_client.get_repo(github_view.full_repo_name) issue = repo.get_issue(github_view.issue_number) if issue.labels: diff --git a/enterprise/integrations/github/github_view.py b/enterprise/integrations/github/github_view.py index a37ae04c33..c11eafb9ee 100644 --- a/enterprise/integrations/github/github_view.py +++ b/enterprise/integrations/github/github_view.py @@ -735,7 +735,7 @@ class GithubFactory: payload['installation']['id'] ).token - with Github(access_token) as gh: + with Github(auth=Auth.Token(access_token)) as gh: repo = gh.get_repo(selected_repo) login = ( payload['organization']['login'] @@ -872,7 +872,7 @@ class GithubFactory: access_token = integration.get_access_token(installation_id).token head_ref = None - with Github(access_token) as gh: + with Github(auth=Auth.Token(access_token)) as gh: repo = gh.get_repo(selected_repo) pull_request = repo.get_pull(issue_number) head_ref = pull_request.head.ref diff --git a/enterprise/integrations/utils.py b/enterprise/integrations/utils.py index 6ead2e642d..f92f3facc0 100644 --- a/enterprise/integrations/utils.py +++ b/enterprise/integrations/utils.py @@ -20,6 +20,7 @@ from openhands.events.action import ( AgentFinishAction, MessageAction, ) +from openhands.events.event_filter import EventFilter from openhands.events.event_store_abc import EventStoreABC from openhands.events.observation.agent import AgentStateChangedObservation from openhands.integrations.service_types import Repository @@ -203,18 +204,27 @@ def get_summary_for_agent_state( def get_final_agent_observation( event_store: EventStoreABC, ) -> list[AgentStateChangedObservation]: - return event_store.get_matching_events( - source=EventSource.ENVIRONMENT, - event_types=(AgentStateChangedObservation,), - limit=1, + events = event_store.search_events( reverse=True, + limit=1, + filter=EventFilter( + source=EventSource.ENVIRONMENT.value, + include_types=(AgentStateChangedObservation,), + ), ) + return [e for e in events if isinstance(e, AgentStateChangedObservation)] def get_last_user_msg(event_store: EventStoreABC) -> list[MessageAction]: - return event_store.get_matching_events( - source=EventSource.USER, event_types=(MessageAction,), limit=1, reverse='true' + events = event_store.search_events( + reverse=True, + limit=1, + filter=EventFilter( + source=EventSource.USER.value, + include_types=(MessageAction,), + ), ) + return [e for e in events if isinstance(e, MessageAction)] def extract_summary_from_event_store( @@ -226,13 +236,18 @@ def extract_summary_from_event_store( conversation_link = CONVERSATION_URL.format(conversation_id) summary_instruction = get_summary_instruction() - instruction_event: list[MessageAction] = event_store.get_matching_events( - query=json.dumps(summary_instruction), - source=EventSource.USER, - event_types=(MessageAction,), - limit=1, + instruction_events = event_store.search_events( reverse=True, + limit=1, + filter=EventFilter( + query=json.dumps(summary_instruction), + source=EventSource.USER.value, + include_types=(MessageAction,), + ), ) + instruction_event: list[MessageAction] = [ + e for e in instruction_events if isinstance(e, MessageAction) + ] final_agent_observation = get_final_agent_observation(event_store) @@ -247,15 +262,20 @@ def extract_summary_from_event_store( event_id: int = instruction_event[0].id - agent_messages: list[MessageAction | AgentFinishAction] = ( - event_store.get_matching_events( - start_id=event_id, - source=EventSource.AGENT, - event_types=(MessageAction, AgentFinishAction), - reverse=True, - limit=1, - ) + agent_messages_events = event_store.search_events( + start_id=event_id, + reverse=True, + limit=1, + filter=EventFilter( + source=EventSource.AGENT.value, + include_types=(MessageAction, AgentFinishAction), + ), ) + agent_messages: list[MessageAction | AgentFinishAction] = [ + e + for e in agent_messages_events + if isinstance(e, (MessageAction, AgentFinishAction)) + ] if len(agent_messages) == 0: logger.warning( diff --git a/openhands/core/logger.py b/openhands/core/logger.py index 2fabb6f350..1ea620b6ab 100644 --- a/openhands/core/logger.py +++ b/openhands/core/logger.py @@ -552,11 +552,11 @@ def get_uvicorn_json_log_config() -> dict: }, # Actual JSON formatters used by handlers below 'json': { - '()': 'pythonjsonlogger.jsonlogger.JsonFormatter', + '()': 'pythonjsonlogger.json.JsonFormatter', 'fmt': '%(message)s %(levelname)s %(name)s %(asctime)s %(exc_info)s', }, 'json_access': { - '()': 'pythonjsonlogger.jsonlogger.JsonFormatter', + '()': 'pythonjsonlogger.json.JsonFormatter', 'fmt': '%(message)s %(levelname)s %(name)s %(asctime)s %(client_addr)s %(request_line)s %(status_code)s', }, },