Skip to content

fix: initialize is_successful to avoid NameError in push_inline_code_suggestions - #3

Closed
esti-am wants to merge 1 commit into
mainfrom
fix/code-suggestions-uninitialized-is-successful
Closed

esti-am wants to merge 1 commit into
mainfrom
fix/code-suggestions-uninitialized-is-successful

Conversation

@esti-am

@esti-am esti-am commented Oct 21, 2026

Copy link
Copy Markdown

Summary

Fixes a real NameError found by GitHub Code Scanning (CodeQL rule py/uninitialized-local-variable) on main.

In PRCodeSuggestions.push_inline_code_suggestions, is_successful is only assigned inside the if suggestions_to_publish: branch, but is referenced unconditionally later:

if code_suggestions and not is_successful:

suggestions_to_publish = artifact_suggestions if supports_suggestions_artifact else code_suggestions. When supports_suggestions_artifact is True and artifact_suggestions is empty while code_suggestions is non-empty, suggestions_to_publish is falsy, the assignment branch never runs, and the later reference raises NameError at runtime.

Changes

Initialize is_successful = False alongside the other state variables at the top of the method, matching the pattern already used for artifact_batch_published.

Testing

  • ruff check pr_agent/tools/pr_code_suggestions.py - clean
  • pytest tests/unittest/test_pr_code_suggestions_lifecycle.py tests/unittest/test_git_provider_code_suggestions.py tests/unittest/test_gitlab_batch_publish_suggestions.py - all passing
  • pytest tests/unittest/test_pr_code_suggestions_core.py - 293/313 passing; the 20 failures are pre-existing and unrelated (sandbox network blocks a tiktoken encoding download over HTTPS, SSLCertVerificationError), none touch push_inline_code_suggestions or is_successful

Context

Part of a sweep triaging the 187 open CodeQL alerts on this repo's main, per Ira's instruction to resolve what's fixable in PRs and dismiss false positives/irrelevant findings for the rest.

🤖 Generated with Claude Code

…suggestions

is_successful was only ever assigned inside the `if suggestions_to_publish:`
branch, but referenced unconditionally afterward. When
supports_suggestions_artifact is True and artifact_suggestions is empty
while code_suggestions is non-empty, suggestions_to_publish resolves to an
empty list, so is_successful is never assigned before the
`if code_suggestions and not is_successful:` check, raising a NameError.

Found via CodeQL alert py/uninitialized-local-variable on Agrematch/pr-agent.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@esti-am esti-am added the bug Something isn't working label Oct 21, 2026
@esti-am
esti-am requested a review from ira-at-work October 21, 2026 11:00
@ira-at-work
ira-at-work deleted the fix/code-suggestions-uninitialized-is-successful branch October 21, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants