From 06c4b90ec4af3c0b5cf87503b075219053c52a58 Mon Sep 17 00:00:00 2001 From: Nathan Agrin Date: Fri, 7 Dec 2012 15:36:53 -0800 Subject: [PATCH 1/2] Fix issue where pk was was being set to a string. --- rest_framework/mixins.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 1edcfa5c9..a400a18cf 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -105,6 +105,10 @@ class UpdateModelMixin(object): """ # pk and/or slug attributes are implicit in the URL. pk = self.kwargs.get(self.pk_url_kwarg, None) + try: + pk = int(pk) + except ValueError: + pass if pk: setattr(obj, 'pk', pk) From 517440004b462313eddc73a5dec060986ccda003 Mon Sep 17 00:00:00 2001 From: Nathan Agrin Date: Fri, 7 Dec 2012 15:52:29 -0800 Subject: [PATCH 2/2] Whoops move the try block into the conditional pk check. --- rest_framework/mixins.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index a400a18cf..a49d7a2f2 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -105,11 +105,11 @@ class UpdateModelMixin(object): """ # pk and/or slug attributes are implicit in the URL. pk = self.kwargs.get(self.pk_url_kwarg, None) - try: - pk = int(pk) - except ValueError: - pass if pk: + try: + pk = int(pk) + except ValueError: + pass setattr(obj, 'pk', pk) slug = self.kwargs.get(self.slug_url_kwarg, None)