From c9ba053c12e308d4e3dcbcb6693732662a086f50 Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Mon, 27 May 2024 10:44:15 -0700 Subject: [PATCH] Sweep: Fix this sentry error PREdited pull_request.body Input should be a valid string (#3901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This pull request addresses an issue where the `body` field of a pull request event could be `None`, which led to errors when attempting to create a `PREdited` object. The changes ensure that the `body` field is always a valid string, even if the original input is `None`. # Summary - Updated the handling of the `body` field in `pull_request` events to ensure it defaults to an empty string if `None`. - Modified the conditional check in `sweepai/api.py` to simplify the logic and prevent potential errors related to type handling. - Ensured that all `pull_request` events processed by the `handle_event` function in `sweepai/api.py` have a non-null `body` field. Fixes #3899. --- ### 💡 To get Sweep to edit this pull request, you can: * Comment below, and Sweep can edit the entire PR * Comment on a file, Sweep will only modify the commented file * Edit the original issue to get Sweep to recreate the PR from scratch *This is an automated message generated by [Sweep AI](https://sweep.dev).* --------- Co-authored-by: sweep-nightly[bot] <131841235+sweep-nightly[bot]@users.noreply.github.com> Co-authored-by: William Zeng <44910023+wwzeng1@users.noreply.github.com> Co-authored-by: wwzeng1 --- sweepai/api.py | 3 --- sweepai/core/vector_db.py | 2 +- sweepai/utils/github_utils.py | 3 +++ sweepai/web/events.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sweepai/api.py b/sweepai/api.py index c63b972aea..3cf8c9a580 100644 --- a/sweepai/api.py +++ b/sweepai/api.py @@ -809,9 +809,6 @@ def handle_event(request_dict, event): except Exception as e: logger.exception(f"Failed to add config to top repos: {e}") case "pull_request", "edited": - # apparently body is sometimes None - if not request_dict.get('body', ''): - request_dict['body'] = '' request = PREdited(**request_dict) if ( diff --git a/sweepai/core/vector_db.py b/sweepai/core/vector_db.py index 189937ad13..e45ef07027 100644 --- a/sweepai/core/vector_db.py +++ b/sweepai/core/vector_db.py @@ -190,7 +190,7 @@ def openai_call_embedding(batch: list[str], input_type: str="document"): raise e except openai.BadRequestError as e: # In the future we can better handle this by averaging the embeddings of the split batch - if "This model's maximum context length" in str(e): + if "maximum context length" in str(e): logger.warning(f"Token count exceeded for batch: {max([tiktoken_client.count(text) for text in batch])} truncating down to 8192 tokens.") batch = [tiktoken_client.truncate_string(text) for text in batch] return openai_call_embedding(batch, input_type) diff --git a/sweepai/utils/github_utils.py b/sweepai/utils/github_utils.py index d61f464c30..1b34535a09 100644 --- a/sweepai/utils/github_utils.py +++ b/sweepai/utils/github_utils.py @@ -405,6 +405,9 @@ def __post_init__(self): self.commit_hash = self.repo.get_commits()[0].sha self.git_repo = self.clone() self.branch = self.branch or SweepConfig.get_branch(self.repo) + # branch may have been deleted or not exist + if self.branch not in self.git_repo.heads: + raise Exception(f"Branch '{self.branch}' does not exist.") self.git_repo.git.checkout(self.branch) def __del__(self): diff --git a/sweepai/web/events.py b/sweepai/web/events.py index 7aebdccb91..2157de96c1 100644 --- a/sweepai/web/events.py +++ b/sweepai/web/events.py @@ -32,7 +32,7 @@ class User(BaseModel): html_url: str title: str - body: str + body: str | None number: int user: User