Fix: return 404 instead of 500 for invalid advisory IDs - #2400
Open
gorasatryanGH wants to merge 2 commits into
Open
Fix: return 404 instead of 500 for invalid advisory IDs#2400gorasatryanGH wants to merge 2 commits into
gorasatryanGH wants to merge 2 commits into
Conversation
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
force-pushed
the
fix/advisory-404-instead-of-500
branch
from
July 30, 2026 11:47
a79e516 to
87d8451
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2396
Problem
AdvisoryV2QuerySet.latest_for_avid()usedself.get(...), which raisesAdvisoryV2.DoesNotExistwhen no matching row exists. The three views thatcall it (
AdvisoryDetails,AdvisoryPackagesDetails,AdvisoryPackageCommitPatchDetails) all expect a falsy return value so theycan raise
Http404themselves — so the exception propagated unhandled andDjango returned a 500 instead of a 404 for any invalid/unknown avid.
Fix
Catch
DoesNotExistinlatest_for_avid()and returnNone, matching whatcallers already expect. Query count is unchanged (still 1 query).
Tests
latest_for_avid()returns
Nonefor an unknown avid.a 404 response for an invalid avid.
reported 500) and pass with the fix.
AdvisoryV2(models, api_v2, advisorymerge) — all green.