Skip to content

Fix crashes and unclosed anchor tags in advisory curation views - #2507

Open
Adnan9-63 wants to merge 3 commits into
aboutcode-org:mainfrom
Adnan9-63:fix/2478-advisory-curation-crash
Open

Adnan9-63 wants to merge 3 commits into
aboutcode-org:mainfrom
Adnan9-63:fix/2478-advisory-curation-crash

Conversation

@Adnan9-63

Copy link
Copy Markdown

What changes does this PR introduce?

This PR addresses issue #2478 by fixing crashes in AdvisoryMitigationCurationView and resolving broken table markup in advisory_todos.html.

Specifically:

  1. Prevent StopIteration & AttributeError in AdvisoryMitigationCurationView:
    • Filters adv.summary and adv.summary.strip() to prevent AttributeError when summary is None.
    • Safely guards next(iter(advisory_summaries)) by falling back to first_advisory.avid or None if summaries are empty.
    • Safely guards first_advisory.impacted_packages so TODO items with 0 advisories return an empty curation_items list rather than raising an AttributeError.
  2. Template Symmetry in advisory_todos.html:
    • Ensures the closing </a> tag is rendered for CONFLICTING_SEVERITY_SCORES, CONFLICTING_WEAKNESSES, and MISSING_FIXED_BY_PACKAGE (previously only supported_curation types closed </a>, leaving the other types unclosed).
  3. Template Guard in mitigation_curation.html:
    • Wrapped the advisory header link with {% if avid %} to avoid reverse URL lookup errors when avid is None.
  4. Unit Tests:
    • Added AdvisoryCurationViewTestCase in vulnerabilities/tests/test_view.py testing mitigation curation with empty/whitespace summaries, 0 advisories, and full anchor tag closure across all issue types in advisory_todos.html.

Fixes #2478

Checklist

  • Code passes black --check and isort --check
  • Unit tests pass: pytest vulnerabilities/tests/test_view.py -k AdvisoryCurationViewTestCase
  • DCO sign-off applied to commit

Signed-off-by: Muhammad Adnan <muhammad1414114@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@Adnan9-63
Adnan9-63 requested a lite review from Copilot November 17, 2026 09:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@kmlyz kmlyz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on #2478! A few things stood out while testing:

  • In vulnerabilities/views.py, the other three curation views (package, severity, weakness) still index issue_detail["curation_items"] directly and raise a KeyError when empty, so .get("curation_items", []) could help there too.
  • In AdvisoryMitigationCurationView, if the first advisory has no summary and a second one does, avid comes from the second while curation_items still reads from the first.
  • The anchor test only checks the opening has-text-info tag, so it still passes without a closing </a>.

Signed-off-by: Muhammad Adnan <muhammad1414114@gmail.com>
@Adnan9-63

Adnan9-63 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Thanks for the thorough review @kmlyz! I have pushed commit f366dbbe addressing all three points:

  1. KeyError guard across curation views: Replaced issue_detail["curation_items"] with issue_detail.get("curation_items", []) in AdvisoryPackageCurationView, AdvisorySeverityCurationView, and AdvisoryWeaknessCurationView, and guarded summary stripping against None.
  2. Consistent advisory selection: Updated AdvisoryMitigationCurationView to select a single selected_advisory (first advisory with a non-empty summary, falling back to todo.advisories.first()) so both context["avid"] and context["curation_items"] always derive from the same advisory.
  3. Strengthened unit tests: Added tests covering advisory selection consistency and missing curation_items keys, and updated test_advisory_todos_template_renders_closed_anchors to parse the rendered HTML with BeautifulSoup and assert exact <a> / </a> closure per cell.

@kmlyz kmlyz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, @Adnan9-63. The curation view KeyError guards and advisory selection consistency look good now and the 5 AdvisoryCurationViewTestCase tests pass.

One small catch on the anchor test: BeautifulSoup with html.parser auto-closes unclosed anchor tags when serializing str(td), so checking </a> on the parsed soup still passes even if the closing tag is missing in the template. Checking the raw response content directly (for example per raw td cell) would catch a regression.

Signed-off-by: Muhammad Adnan <muhammad1414114@gmail.com>
@Adnan9-63

Copy link
Copy Markdown
Author

Good catch @kmlyz — html.parser silently auto-closes missing </a> tags during serialization. I pushed a50befff updating test_advisory_todos_template_renders_closed_anchors to extract each <td ...>...</td> cell directly from the raw response.content HTML and assert both <a / </a> counts and tag ordering (<a before </a>), while keeping the BeautifulSoup structural assertion.

@kmlyz kmlyz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the test, @Adnan9-63. Checked commit a50beff and verified that reverting the closing anchor tag now fails the raw cell assertion while all five AdvisoryCurationViewTestCase tests pass.

Everything looks good from my side.

This branch has not been deployed

No deployments
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.

Fix unhandled StopIteration/AttributeError crashes and unclosed <a> tags in Advisory Curation views

3 participants