Skip to content

fix: prevent KeyError when removing type from PR description data#2271

Open
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt:fix/pr-description-type-keyerror
Open

fix: prevent KeyError when removing type from PR description data#2271
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt:fix/pr-description-type-keyerror

Conversation

@wishhyt
Copy link
Copy Markdown

@wishhyt wishhyt commented Mar 18, 2026

Summary

  • When enable_pr_type is False, self.data.pop('type') raises KeyError if the AI response YAML does not contain a type field
  • This is inconsistent with the adjacent labels removal which guards with if 'labels' in self.data before popping
  • Use pop('type', None) for safe removal

Changes

pr_agent/tools/pr_description.py: Changed self.data.pop('type') to self.data.pop('type', None)

Test plan

  • Verify that /describe works correctly when enable_pr_type is False and AI response omits the type field
  • Verify normal behavior when type field is present

When `enable_pr_type` is False, `self.data.pop('type')` raises
KeyError if the AI response YAML does not contain a 'type' field.
Use `pop('type', None)` for safe removal, consistent with the
adjacent `labels` removal which already guards with an `in` check.

Made-with: Cursor
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Prevent KeyError when removing type from PR description

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Prevent KeyError when removing type field from PR description
• Use safe pop with default None value for consistency
• Handles cases where AI response omits type field
Diagram
flowchart LR
  A["enable_pr_type is False"] -- "type field missing" --> B["pop without default"]
  B -- "raises KeyError" --> C["Error"]
  A -- "type field missing" --> D["pop with None default"]
  D -- "returns None safely" --> E["Success"]
Loading

Grey Divider

File Changes

1. pr_agent/tools/pr_description.py 🐞 Bug fix +1/-1

Safe removal of optional type field

• Changed self.data.pop('type') to self.data.pop('type', None)
• Prevents KeyError when type field is absent from AI response
• Aligns with existing safe removal pattern for labels field

pr_agent/tools/pr_description.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Mar 18, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant