fix(gitlab): add null check for target_file in publish_code_suggestions#2316
Open
fix(gitlab): add null check for target_file in publish_code_suggestions#2316
Conversation
In publish_code_suggestions(), target_file can be None if the suggestion's file is not found in the diff. The code then accesses target_file.head_file which crashes with AttributeError. Add a None check to skip the suggestion with a warning log when the file is missing from the diff. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Review Summary by QodoAdd null check for target_file in GitLab publish_code_suggestions
WalkthroughsDescription• Add null check for target_file before dereferencing in GitLab provider • Prevents AttributeError when suggestion file not found in diff • Logs warning and skips suggestion gracefully instead of crashing • Allows remaining suggestions to be published successfully Diagramflowchart LR
A["Suggestion file lookup"] --> B{"target_file found?"}
B -->|Yes| C["Process suggestion"]
B -->|No| D["Log warning and skip"]
C --> E["Publish suggestion"]
D --> F["Continue to next"]
File Changes1. pr_agent/git_providers/gitlab_provider.py
|
Contributor
Code Review by Qodo
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GitLabProvider.publish_code_suggestions(),target_fileis initialized toNoneand set only if a matching file is found in the diff. If no match is found, the code proceeds to accesstarget_file.head_file, causing anAttributeError.Nonecheck after the file-search loop: iftarget_fileisNone, log a warning andcontinueto skip that suggestion gracefully.Test plan
publish_code_suggestionsflow for GitLab MRs🤖 Generated with Claude Code