[Patchew-devel] [PATCH] fix remaining 500 occurrences

Paolo Bonzini posted 1 patch 5 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20190416082354.4753-1-pbonzini@redhat.com
api/models.py        | 2 +-
mods/diff.py         | 2 ++
mods/maintainer.py   | 1 +
patchew/logviewer.py | 2 +-
www/views.py         | 2 ++
5 files changed, 7 insertions(+), 2 deletions(-)
[Patchew-devel] [PATCH] fix remaining 500 occurrences
Posted by Paolo Bonzini 5 years ago
With template logs disabled, the error logs are actually readable
and it is possible to sift through them and fix all the remaining
occurrences of internal server errors (exceptions during request
processing).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/models.py        | 2 +-
 mods/diff.py         | 2 ++
 mods/maintainer.py   | 1 +
 patchew/logviewer.py | 2 +-
 www/views.py         | 2 ++
 5 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/api/models.py b/api/models.py
index b4a6e9e..aa99eb8 100644
--- a/api/models.py
+++ b/api/models.py
@@ -673,7 +673,7 @@ class Message(models.Model):
             d.day, d.hour, d.minute, d.second, d.year)
 
     def get_last_reply_age(self):
-        return self._get_age(self.last_reply_date)
+        return self._get_age(self.last_reply_date or self.date)
 
     def get_body(self):
         return self.get_mbox_obj().get_body()
diff --git a/mods/diff.py b/mods/diff.py
index 4896f41..a44b637 100644
--- a/mods/diff.py
+++ b/mods/diff.py
@@ -110,6 +110,8 @@ class DiffModule(PatchewModule):
     def www_view_series_diff(self, request, project, series_left, series_right):
         sl = Message.objects.filter(project__name=project, message_id=series_left)
         sr = Message.objects.filter(project__name=project, message_id=series_right)
+        if sl is None or sr is None:
+            raise Http404("Series not found")
         return render_page(request, "series-diff.html",
                            series_left=self._get_series_for_diff(sl),
                            series_right=self._get_series_for_diff(sr))
diff --git a/mods/maintainer.py b/mods/maintainer.py
index 4d02dba..7093760 100644
--- a/mods/maintainer.py
+++ b/mods/maintainer.py
@@ -10,6 +10,7 @@
 
 import re
 from django.conf.urls import url
+from django.core.exceptions import PermissionDenied
 from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest
 from django.urls import reverse
 from mod import PatchewModule
diff --git a/patchew/logviewer.py b/patchew/logviewer.py
index f986727..646171c 100644
--- a/patchew/logviewer.py
+++ b/patchew/logviewer.py
@@ -12,7 +12,7 @@ import abc
 import sys
 
 from django.views import View
-from django.http import HttpResponse, StreamingHttpResponse
+from django.http import HttpResponse, StreamingHttpResponse, Http404
 from django.utils.safestring import mark_safe
 
 class ANSIProcessor(object):
diff --git a/www/views.py b/www/views.py
index c8570ca..f48a8ce 100644
--- a/www/views.py
+++ b/www/views.py
@@ -361,6 +361,8 @@ def view_series_message(request, project, thread_id, message_id):
     if not s:
         raise Http404("Series not found")
     m = api.models.Message.objects.filter(message_id=message_id, in_reply_to=thread_id).first()
+    if not m:
+        raise Http404("Message not found")
     nav_path = prepare_navigate_list(
         "View patch",
         ("series_list", {"project": project}, project),
-- 
2.21.0

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel