Skip to content

fix(views): return empty fixed-package details for unknown purls - #2502

Open
sanchit955 wants to merge 1 commit into
aboutcode-org:mainfrom
sanchit955:fix/affected-by-unknown-purl-500
Open

sanchit955 wants to merge 1 commit into
aboutcode-org:mainfrom
sanchit955:fix/affected-by-unknown-purl-500

Conversation

@sanchit955

Copy link
Copy Markdown

Fixes #2501

The affected-by-advisories v2 page 500s for any purl with no matching package in the database: for_purl(purl).first() returns None and get_fixed_package_details() dereferences it (AttributeError: 'NoneType' object has no attribute 'affected_in_impacts').

This makes get_fixed_package_details() return an empty mapping when the package is None, so the page renders zero results instead of a 500. The template already reads the value through the get_item filter, so an empty mapping renders cleanly. PackageV2Details is unaffected — there self.object is never None.

Tests

  • New AffectedByAdvisoriesListViewTestCase in vulnerabilities/tests/test_view.py: an unknown purl returns 200, an empty fixed_package_details and an empty page. The test fails on unmodified main and passes with the fix.
  • Full vulnerabilities/tests/test_view.py on PostgreSQL 16: 13 passed; the one failure is the pre-existing flaky timing assertion in test_aggregate_fixed_and_affected_packages (it asserts a request completes in under 0.06 s; it fails on unmodified main too).
  • black --check clean on both changed files.

The affected-by-advisories v2 page crashed with AttributeError when the
requested purl has no matching package in the database: for_purl().first()
returns None and get_fixed_package_details() dereferenced it. Return an
empty mapping for a missing package so the page renders zero results
instead of a 500.

Add a regression test covering an unknown purl.

Signed-off-by: Sanchit <dev.sanchit955@gmail.com>
@sanchit955
sanchit955 force-pushed the fix/affected-by-unknown-purl-500 branch from 53570d4 to dc477a9 Compare November 16, 2026 09:06

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.

Affected-by-advisories v2 page returns 500 for a purl with no matching package

1 participant