Browse Source

Handle topic ID 0 in topic_by_id36 root factory

This causes an internal server occasionally from people trying to see if
there's a topic with ID 0 (often via tild.es/0), so this will just
return a 404 instead.
merge-requests/72/head
Deimos 5 years ago
parent
commit
f6088373cd
  1. 9
      tildes/tildes/resources/topic.py

9
tildes/tildes/resources/topic.py

@ -3,7 +3,7 @@
"""Root factories for topics."""
from pyramid.httpexceptions import HTTPFound
from pyramid.httpexceptions import HTTPFound, HTTPNotFound
from pyramid.request import Request
from webargs.pyramidparser import use_kwargs
@ -16,11 +16,16 @@ from tildes.schemas.topic import TopicSchema
@use_kwargs(TopicSchema(only=("topic_id36",)), locations=("matchdict",))
def topic_by_id36(request: Request, topic_id36: str) -> Topic:
"""Get a topic specified by {topic_id36} in the route (or 404)."""
try:
topic_id = id36_to_id(topic_id36)
except ValueError:
raise HTTPNotFound
query = (
request.query(Topic)
.include_deleted()
.include_removed()
.filter_by(topic_id=id36_to_id(topic_id36))
.filter_by(topic_id=topic_id)
)
topic = get_resource(request, query)

Loading…
Cancel
Save