Permalink
Browse files

if object not found raise ObjectDoesNotExist so that tastypie returns…

… 404
  • Loading branch information...
1 parent be9ba1a commit 2850be9f17c691e7fb3f6d9c773269c073df6ecf Alper Kanat committed Oct 22, 2013
Showing with 9 additions and 5 deletions.
  1. +9 −5 tastypie_mongodb/resources.py
@@ -2,6 +2,7 @@
from bson import ObjectId
+from django.core.exceptions import ObjectDoesNotExist
from tastypie.bundle import Bundle
from tastypie.resources import Resource
@@ -30,11 +31,14 @@ def obj_get(self, request=None, **kwargs):
"""
Returns mongodb document from provided id.
"""
- return self.get_object_class()(
- self.get_collection().find_one({
- "_id": ObjectId(kwargs.get("pk"))
- })
- )
+ obj = self.get_collection().find_one({
+ "_id": ObjectId(kwargs.get("pk"))
+ })
+
+ if not obj:
+ raise ObjectDoesNotExist
+
+ return self.get_object_class()(obj)
def obj_create(self, bundle, **kwargs):
"""

0 comments on commit 2850be9

Please sign in to comment.