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

Loading…
Cancel
Save