Skip to content

Commit

Permalink
Fix error when linkrot checking with an ID that does not exist in the…
Browse files Browse the repository at this point in the history
… webring
  • Loading branch information
le717 committed Jun 8, 2024
1 parent 33f4b81 commit 5c38281
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _Released TDB_
- Add ability to control showing rotted and same-origin results for root entrypoint and simple embed
- Add readme sections to explain new filtering and embed features
- Ensure the `date_added` field is expressed in UTC
- Fix error when linkrot checking with an ID that does not exist in the webring
- Replace `requests` with `python-httpx`
- Update OpenAPI spec version
- Update minimum Python version to 3.11
Expand Down
7 changes: 5 additions & 2 deletions src/core/database/linkrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ def check_all() -> list[RotResult]:
return [check_one(link.id) for link in weblink.get_all()]


def check_one(uuid: str) -> RotResult:
def check_one(uuid: str) -> RotResult | None:
"""Check a single link for rotting."""
# The uuid doesn't exist in the db, we can't do anything
if (link := weblink.get(uuid)) is None:
return None

# The site could be pinged, so we all good
link = weblink.get(uuid)
if __ping_url(link.url):
result = RotResult(
id=link.id,
Expand Down
6 changes: 5 additions & 1 deletion src/views/linkrot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from flask.views import MethodView
from flask_smorest import abort

from src.blueprints import linkrot
from src.core import models
Expand All @@ -22,7 +23,10 @@ class LinkRotSingleCheck(MethodView):
@linkrot.arguments(models.AuthKey, location="query", as_kwargs=True)
@linkrot.arguments(models.WebLinkId, location="path", as_kwargs=True)
@linkrot.response(200, models.RotResult)
@linkrot.alt_response(404, schema=models.HttpError)
def post(self, **kwargs: Any) -> models.RotResult:
"""Check a single link in the ring for link rot."""
del kwargs["auth_key"]
return db.check_one(str(kwargs["id"]))
if (result := db.check_one(str(kwargs["id"]))) is None:
abort(404, message="That ID does not exist in the webring.")
return result

0 comments on commit 5c38281

Please sign in to comment.