Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save colinsullivan/818661 to your computer and use it in GitHub Desktop.
Save colinsullivan/818661 to your computer and use it in GitHub Desktop.
From 0952e591e94a44afaa0ac27eff1f4f71c6423627 Mon Sep 17 00:00:00 2001
From: Colin Sullivan <colinsul@gmail.com>
Date: Tue, 8 Feb 2011 20:49:37 -0500
Subject: [PATCH] Catch NotFound error instead of all errors...
to create resource if it doesn't exist.
---
tastypie/resources.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tastypie/resources.py b/tastypie/resources.py
index b481421..b76eb4e 100644
--- a/tastypie/resources.py
+++ b/tastypie/resources.py
@@ -983,7 +983,7 @@ class Resource(object):
try:
updated_bundle = self.obj_update(bundle, request=request, pk=kwargs.get('pk'))
return HttpAccepted()
- except:
+ except NotFound:
updated_bundle = self.obj_create(bundle, request=request, pk=kwargs.get('pk'))
return HttpCreated(location=self.get_resource_uri(updated_bundle))
--
1.7.3.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment