Commit d8a74c39 authored by Damien Lespiau's avatar Damien Lespiau
Browse files

patch: Make the /patch/msgid/ view resilient to duplicate msgids

In case of cross posting on mailing-lists handled by patchwork we have
duplicated msgids in the DB. So we need to make a choice when asked for
the patch with a give msgid. Otherwise:

Internal Server Error: /patch/msgid/
Traceback (most recent call last):
  File "django/core/handlers/", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "patchwork/views/", line 128, in msgid
    patch = get_object_or_404(Patch, msgid='<' + msgid + '>')
  File "", line 155, in get_object_or_404
    return queryset.get(*args, **kwargs)
  File "django/db/models/", line 338, in get
    (self.model._meta.object_name, num)
MultipleObjectsReturned: get() returned more than one Patch -- it returned 2!
Signed-off-by: default avatarDamien Lespiau <>
parent aa6522c6
......@@ -19,7 +19,7 @@
from __future__ import absolute_import
from django.http import HttpResponse, HttpResponseForbidden
from django.http import HttpResponse, HttpResponseForbidden, Http404
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.utils import six
......@@ -124,6 +124,13 @@ def list(request, project_id):
return render_to_response('patchwork/list.html', context)
def _get_patch_or_404(request, msgid):
patch = Patch.objects.filter(msgid='<' + msgid + '>').first()
if patch is None:
raise Http404("Patch not found")
return patch
def msgid(request, msgid):
patch = get_object_or_404(Patch, msgid='<' + msgid + '>')
patch = _get_patch_or_404(Patch, msgid)
return redirect(patch)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment