Author: kmtracey
Date: 2010-03-16 17:45:42 -0500 (Tue, 16 Mar 2010)
New Revision: 12801

Modified:
   django/branches/releases/1.1.X/
   django/branches/releases/1.1.X/django/contrib/comments/views/comments.py
   
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/fixtures/comment_tests.json
   django/branches/releases/1.1.X/tests/regressiontests/comment_tests/models.py
   
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/tests/comment_view_tests.py
Log:
[1.1.X] Changed the comments post view code to avoid raising an exception if 
handed invalid data for the object pk. Thanks to Leo for the test.

r12800 from trunk.



Property changes on: django/branches/releases/1.1.X
___________________________________________________________________
Name: svnmerge-integrated
   - 
/django/trunk:1-11500,11523,11527-11528,11531-11552,11554,11577,11579-11581,11588-11589,11591-11592,11596-11599,11601-11617,11619-11626,11628-11635,11637-11638,11643-11644,11648-11653,11656,11670,11678,11681,11684,11686,11688,11691,11693,11695,11697,11699,11701,11703,11705,11707,11714,11719,11732,11734,11740,11748,11751,11753,11756,11760,11800,11802,11808,11815,11817,11820,11822,11824,11826,11828,11831,11833,11835,11837,11839,11841,11844,11857,11864,11874,11876,11878,11885,11898,11901,11905,11909,11912,11914,11917,11938,11953,11961,11977,11979,11984,11986,11988,11990,11992,11994,11996,11998,12001,12004,12006,12011,12022,12024,12044-12045,12048,12054-12056,12059,12064,12066,12068,12070,12079,12086,12088,12104,12118,12132,12137-12138,12140-12141,12144,12150-12152,12220-12221,12229,12249,12253,12276,12282,12284,12293,12313,12317-12324,12333,12341,12343,12346,12353,12362,12379,12384,12398,12405,12408-12411,12419-12420,12423,12425-12426,12429,12434,12436,12439-12442,12447-12448,12457,12461-12464,12467,12471,12473,12475,12484,12489-12490,12492,12497-12498,12502,12505,12513,12515-12516,12518,12523,12526,12528,12533,12535,12537,12539,12541,12548,12553,12556,12558-12560,12562,12567,12569-12570,12573,12576,12579,12581,12584,12598-12599,12602,12605,12614,12616,12621-12622,12627,12630-12631,12635,12637,12639,12641,12644,12646,12648,12650,12652,12654,12657,12659,12661,12663,12665,12667,12669,12671,12673,12676,12679,12681,12683,12686,12688,12694,12696,12698,12700,12704-12705,12710-12712,12719,12721,12723,12725-12726,12728,12733-12734,12737,12739,12774,12795
   + 
/django/trunk:1-11500,11523,11527-11528,11531-11552,11554,11577,11579-11581,11588-11589,11591-11592,11596-11599,11601-11617,11619-11626,11628-11635,11637-11638,11643-11644,11648-11653,11656,11670,11678,11681,11684,11686,11688,11691,11693,11695,11697,11699,11701,11703,11705,11707,11714,11719,11732,11734,11740,11748,11751,11753,11756,11760,11800,11802,11808,11815,11817,11820,11822,11824,11826,11828,11831,11833,11835,11837,11839,11841,11844,11857,11864,11874,11876,11878,11885,11898,11901,11905,11909,11912,11914,11917,11938,11953,11961,11977,11979,11984,11986,11988,11990,11992,11994,11996,11998,12001,12004,12006,12011,12022,12024,12044-12045,12048,12054-12056,12059,12064,12066,12068,12070,12079,12086,12088,12104,12118,12132,12137-12138,12140-12141,12144,12150-12152,12220-12221,12229,12249,12253,12276,12282,12284,12293,12313,12317-12324,12333,12341,12343,12346,12353,12362,12379,12384,12398,12405,12408-12411,12419-12420,12423,12425-12426,12429,12434,12436,12439-12442,12447-12448,12457,12461-12464,12467,12471,12473,12475,12484,12489-12490,12492,12497-12498,12502,12505,12513,12515-12516,12518,12523,12526,12528,12533,12535,12537,12539,12541,12548,12553,12556,12558-12560,12562,12567,12569-12570,12573,12576,12579,12581,12584,12598-12599,12602,12605,12614,12616,12621-12622,12627,12630-12631,12635,12637,12639,12641,12644,12646,12648,12650,12652,12654,12657,12659,12661,12663,12665,12667,12669,12671,12673,12676,12679,12681,12683,12686,12688,12694,12696,12698,12700,12704-12705,12710-12712,12719,12721,12723,12725-12726,12728,12733-12734,12737,12739,12774,12795,12800

Modified: 
django/branches/releases/1.1.X/django/contrib/comments/views/comments.py
===================================================================
--- django/branches/releases/1.1.X/django/contrib/comments/views/comments.py    
2010-03-16 22:37:45 UTC (rev 12800)
+++ django/branches/releases/1.1.X/django/contrib/comments/views/comments.py    
2010-03-16 22:45:42 UTC (rev 12801)
@@ -1,7 +1,7 @@
 from django import http
 from django.conf import settings
 from utils import next_redirect, confirmation_view
-from django.core.exceptions import ObjectDoesNotExist
+from django.core.exceptions import ObjectDoesNotExist, ValidationError
 from django.db import models
 from django.shortcuts import render_to_response
 from django.template import RequestContext
@@ -59,6 +59,10 @@
         return CommentPostBadRequest(
             "No object matching content-type %r and object PK %r exists." % \
                 (escape(ctype), escape(object_pk)))
+    except (ValueError, ValidationError), e:
+        return CommentPostBadRequest(
+            "Attempting go get content-type %r and object PK %r exists raised 
%s" % \
+                (escape(ctype), escape(object_pk), e.__class__.__name__))
 
     # Do we want to preview the comment?
     preview = "preview" in data

Modified: 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/fixtures/comment_tests.json
===================================================================
--- 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/fixtures/comment_tests.json
      2010-03-16 22:37:45 UTC (rev 12800)
+++ 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/fixtures/comment_tests.json
      2010-03-16 22:45:42 UTC (rev 12801)
@@ -1,5 +1,12 @@
 [
   {
+    "model" : "comment_tests.book",
+    "pk" : 1,
+    "fields" : {
+        "dewey_decimal" : "12.34"
+    }
+  },
+  {
     "model" : "comment_tests.author",
     "pk" : 1,
     "fields" : {

Modified: 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/models.py
===================================================================
--- 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/models.py    
    2010-03-16 22:37:45 UTC (rev 12800)
+++ 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/models.py    
    2010-03-16 22:45:42 UTC (rev 12801)
@@ -28,3 +28,7 @@
 
     def __str__(self):
         return self.title
+
+class Book(models.Model):
+    dewey_decimal = models.DecimalField(primary_key = True, decimal_places=2, 
max_digits=5)
+    
\ No newline at end of file

Modified: 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/tests/comment_view_tests.py
===================================================================
--- 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/tests/comment_view_tests.py
      2010-03-16 22:37:45 UTC (rev 12800)
+++ 
django/branches/releases/1.1.X/tests/regressiontests/comment_tests/tests/comment_view_tests.py
      2010-03-16 22:45:42 UTC (rev 12801)
@@ -3,7 +3,7 @@
 from django.contrib.auth.models import User
 from django.contrib.comments import signals
 from django.contrib.comments.models import Comment
-from regressiontests.comment_tests.models import Article
+from regressiontests.comment_tests.models import Article, Book
 from regressiontests.comment_tests.tests import CommentTestCase
 
 post_redirect_re = re.compile(r'^http://testserver/posted/\?c=(?P<pk>\d+$)')
@@ -45,6 +45,22 @@
         response = self.client.post("/post/", data)
         self.assertEqual(response.status_code, 400)
 
+    def testPostInvalidIntegerPK(self):
+        a = Article.objects.get(pk=1)
+        data = self.getValidData(a)
+        data["comment"] = "This is another comment"
+        data["object_pk"] = u'\ufffd'
+        response = self.client.post("/post/", data)
+        self.assertEqual(response.status_code, 400)
+
+    def testPostInvalidDecimalPK(self):
+        b = Book.objects.get(pk='12.34')
+        data = self.getValidData(b)
+        data["comment"] = "This is another comment"
+        data["object_pk"] = 'cookies'
+        response = self.client.post("/post/", data)
+        self.assertEqual(response.status_code, 400)
+
     def testCommentPreview(self):
         a = Article.objects.get(pk=1)
         data = self.getValidData(a)
@@ -187,11 +203,11 @@
         location = response["Location"]
         match = post_redirect_re.match(location)
         self.failUnless(match != None, "Unexpected redirect location: %s" % 
location)
-        
+
         data["next"] = "/somewhere/else/"
         data["comment"] = "This is another comment"
         response = self.client.post("/post/", data)
-        location = response["Location"]        
+        location = response["Location"]
         match = re.search(r"^http://testserver/somewhere/else/\?c=\d+$";, 
location)
         self.failUnless(match != None, "Unexpected redirect location: %s" % 
location)
 
@@ -199,7 +215,7 @@
         a = Article.objects.get(pk=1)
         data = self.getValidData(a)
         response = self.client.post("/post/", data)
-        location = response["Location"]        
+        location = response["Location"]
         match = post_redirect_re.match(location)
         self.failUnless(match != None, "Unexpected redirect location: %s" % 
location)
         pk = int(match.group('pk'))
@@ -216,14 +232,14 @@
         data["next"] = "/somewhere/else/?foo=bar"
         data["comment"] = "This is another comment"
         response = self.client.post("/post/", data)
-        location = response["Location"]        
+        location = response["Location"]
         match = 
re.search(r"^http://testserver/somewhere/else/\?foo=bar&c=\d+$";, location)
         self.failUnless(match != None, "Unexpected redirect location: %s" % 
location)
 
-    def testCommentDoneReSubmitWithInvalidParams(self):
+    def testCommentPostRedirectWithInvalidIntegerPK(self):
         """
-        Tests that attempting to retrieve the location specified in the 
-        post redirect, after adding some invalid data to the expected 
+        Tests that attempting to retrieve the location specified in the
+        post redirect, after adding some invalid data to the expected
         querystring it ends with, doesn't cause a server error.
         """
         a = Article.objects.get(pk=1)
@@ -234,3 +250,4 @@
         broken_location = location + u"\ufffd"
         response = self.client.get(broken_location)
         self.assertEqual(response.status_code, 200)
+

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to