get_document_or_404 raises 404 if given an invalid ObjectId
(and possibly on other errors, not sure what else raises ValidationError)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from django.http import Http404
|
||||
from mongoengine.queryset import QuerySet
|
||||
from mongoengine.base import BaseDocument
|
||||
from mongoengine.base import ValidationError
|
||||
|
||||
def _get_queryset(cls):
|
||||
"""Inspired by django.shortcuts.*"""
|
||||
@@ -25,7 +26,7 @@ def get_document_or_404(cls, *args, **kwargs):
|
||||
queryset = _get_queryset(cls)
|
||||
try:
|
||||
return queryset.get(*args, **kwargs)
|
||||
except queryset._document.DoesNotExist:
|
||||
except (queryset._document.DoesNotExist, ValidationError):
|
||||
raise Http404('No %s matches the given query.' % queryset._document._class_name)
|
||||
|
||||
def get_list_or_404(cls, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user