Skip to content

Return 404 instead of 500 for unknown advisory pages - #2424

Open
MGpromax wants to merge 1 commit into
aboutcode-org:mainfrom
MGpromax:fix-advisory-404
Open

Return 404 instead of 500 for unknown advisory pages#2424
MGpromax wants to merge 1 commit into
aboutcode-org:mainfrom
MGpromax:fix-advisory-404

Conversation

@MGpromax

Copy link
Copy Markdown

Closes #2396

AdvisoryV2QuerySet.latest_for_avid() used .get(), which raises an unhandled AdvisoryV2.DoesNotExist for an unknown avid -- so /advisories/pysec/PYSEC-3000-0 returned a 500. All three detail views that call it (AdvisoryDetails, AdvisoryPackagesDetails, AdvisoryPackageCommitPatchDetails) already do if not advisory: raise Http404(...), i.e. they were written against a returns-None contract the queryset method didn't honor. The fix makes it return None via .filter(...).first().

Added regression tests asserting 404 for unknown avids on the advisory detail and advisory packages pages (with the altcha bot-protection middleware bypassed via the session, following the middleware's own logic).

Tests: the new tests plus test_same_avid_different_content_id.py (which exercises latest_for_avid for existing avids) all pass against postgres locally -- 8 passed.

AdvisoryV2QuerySet.latest_for_avid() used .get() and raised an
unhandled DoesNotExist for an unknown avid, so advisory detail URLs
such as /advisories/pysec/PYSEC-3000-0 returned a server error. All
three detail views calling it already check for a None return and
raise Http404, so return None from the queryset method instead.

Closes aboutcode-org#2396

Signed-off-by: Manoj Gowda <manojgowdabs18@gmail.com>
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