Skip to content

Fix: return 404 instead of 500 for invalid advisory IDs - #2400

Open
gorasatryanGH wants to merge 2 commits into
aboutcode-org:mainfrom
gorasatryanGH:fix/advisory-404-instead-of-500
Open

Fix: return 404 instead of 500 for invalid advisory IDs#2400
gorasatryanGH wants to merge 2 commits into
aboutcode-org:mainfrom
gorasatryanGH:fix/advisory-404-instead-of-500

Conversation

@gorasatryanGH

Copy link
Copy Markdown

Fixes #2396

Problem

AdvisoryV2QuerySet.latest_for_avid() used self.get(...), which raises
AdvisoryV2.DoesNotExist when no matching row exists. The three views that
call it (AdvisoryDetails, AdvisoryPackagesDetails,
AdvisoryPackageCommitPatchDetails) all expect a falsy return value so they
can raise Http404 themselves — so the exception propagated unhandled and
Django returned a 500 instead of a 404 for any invalid/unknown avid.

Fix

Catch DoesNotExist in latest_for_avid() and return None, matching what
callers already expect. Query count is unchanged (still 1 query).

Tests

  • Added a queryset-level regression test asserting latest_for_avid()
    returns None for an unknown avid.
  • Added HTTP-level regression tests for all three affected views, asserting
    a 404 response for an invalid avid.
  • Verified both new tests fail with the original code (reproducing the
    reported 500) and pass with the fix.
  • Ran the wider test suite touching AdvisoryV2 (models, api_v2, advisory
    merge) — all green.

latest_for_avid() raised DoesNotExist instead of returning None, so the Http404 fallback in AdvisoryDetails, AdvisoryPackagesDetails and AdvisoryPackageCommitPatchDetails was never reached.

Fixes aboutcode-org#2396

Signed-off-by: gorasatryanGH <gorasatryan1912@gmail.com>
@gorasatryanGH
gorasatryanGH force-pushed the fix/advisory-404-instead-of-500 branch from a79e516 to 87d8451 Compare July 30, 2026 11:47
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.

Advisory Page Returns 500 Instead of 404 for Invalid Advisory IDs

1 participant