fix(tickets): prevent /review and /describe crash on linked issues with sub-issues#2476
Conversation
…th sub-issues Sub-issue entries built in extract_tickets() omitted the 'labels' key that main-issue entries include. The reviewer/description prompts (and the token_handler pre-pass) render related_tickets under StrictUndefined, so accessing the missing ticket.labels raised UndefinedError, aborting the prompt render before any model call. Add an empty 'labels' key to sub-issue entries and make both templates defensive with 'is defined and', matching the existing ticket.requirements guard. Fixes The-PR-Agent#2471
PR Summary by Qodofix(tickets): avoid StrictUndefined crashes when sub-issues lack labels Description
Diagram
High-Level Assessment
Files changed (3)
|
Sub-issues are regular GitHub issues and can carry labels, so extract them the same way main-issue labels are extracted rather than discarding the data. Falls back to an empty string when there are none, keeping the key present for the StrictUndefined template render.
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require review
Previous review resultsReview updated until commit cda33fd Results up to commit 0cd6ee8
Great, no issues found!Qodo reviewed your code and found no material issues that require review |
|
Code review by qodo was updated up to the latest commit 22ec72b |
|
Code review by qodo was updated up to the latest commit cda33fd |
Problem
When
require_ticket_analysis_reviewis enabled (the default) and a PR references an issue that has sub-issues, both/reviewand/describecrash before any model call with:This leaves a stuck "Preparing review…" placeholder that never resolves.
/improveis unaffected because it doesn't call ticket extraction.Root cause
In
extract_tickets(), main-issue entries include alabelskey but sub-issue entries (sub_issues_content) do not.extract_and_cache_pr_tickets()appends both into the samerelated_ticketslist.The reviewer/description prompts — and the token-counting pre-pass in
token_handler.py— render this list underEnvironment(undefined=StrictUndefined). UnderStrictUndefined,{% if ticket.labels %}on a label-less sub-issue raisesUndefinedErrorinstead of evaluating falsy, aborting the entire prompt render before the LLM request.Fix
Two layers of defense:
ticket_pr_compliance_check.py— add'labels': ""to sub-issue entries so the key is always present.pr_reviewer_prompts.toml/pr_description_prompts.toml— guard with{% if ticket.labels is defined and ticket.labels %}, matching the existingticket.requirementspattern, so the templates are robust against any future label-less entry.Verification
Reproduced with the issue's pinned deps (
dynaconf==3.2.4,Jinja2==3.1.6): the old template fragment crashes withUndefinedErroron a label-less entry, while the new defensive template renders all entry shapes (with labels / missing key / empty string) cleanly.Fixes #2471