#11716: Various methods in django.db.models.fields don't wrap ValueErrors and 
allow
them to escape
---------------------------------------------------+------------------------
          Reporter:  Leo                           |         Owner:  Leo
            Status:  assigned                      |     Milestone:  1.2
         Component:  Database layer (models, ORM)  |       Version:  SVN
        Resolution:                                |      Keywords:     
             Stage:  Accepted                      |     Has_patch:  1  
        Needs_docs:  0                             |   Needs_tests:  0  
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by kmtracey):

 A newly-added test fails with the current patch:

 {{{
 ======================================================================
 ERROR: testCommentDoneReSubmitWithInvalidParams
 (regressiontests.comment_tests.tests.comment_view_tests.CommentViewTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 
"/home/kmt/tmp/django/trunk/tests/regressiontests/comment_tests/tests/comment_view_tests.py",
 line 235, in testCommentDoneReSubmitWithInvalidParams
     response = self.client.get(broken_location)
   File "/home/kmt/tmp/django/trunk/django/test/client.py", line 286, in
 get
     response = self.request(**r)
   File "/home/kmt/tmp/django/trunk/django/core/handlers/base.py", line
 101, in get_response
     response = callback(request, *callback_args, **callback_kwargs)
   File
 "/home/kmt/tmp/django/trunk/django/contrib/comments/views/utils.py", line
 41, in confirmed
     comment = comments.get_model().objects.get(pk=request.GET['c'])
   File "/home/kmt/tmp/django/trunk/django/db/models/manager.py", line 132,
 in get
     return self.get_query_set().get(*args, **kwargs)
   File "/home/kmt/tmp/django/trunk/django/db/models/query.py", line 331,
 in get
     clone = self.filter(*args, **kwargs)
   File "/home/kmt/tmp/django/trunk/django/db/models/query.py", line 545,
 in filter
     return self._filter_or_exclude(False, *args, **kwargs)
   File "/home/kmt/tmp/django/trunk/django/db/models/query.py", line 563,
 in _filter_or_exclude
     clone.query.add_q(Q(*args, **kwargs))
   File "/home/kmt/tmp/django/trunk/django/db/models/sql/query.py", line
 1100, in add_q
     can_reuse=used_aliases)
   File "/home/kmt/tmp/django/trunk/django/db/models/sql/query.py", line
 1040, in add_filter
     connector)
   File "/home/kmt/tmp/django/trunk/django/db/models/sql/where.py", line
 66, in add
     value = obj.prepare(lookup_type, value)
   File "/home/kmt/tmp/django/trunk/django/db/models/sql/where.py", line
 275, in prepare
     return self.field.get_prep_lookup(lookup_type, value)
   File "/home/kmt/tmp/django/trunk/django/db/models/fields/__init__.py",
 line 318, in get_prep_lookup
     return self.get_prep_value(value)
   File "/home/kmt/tmp/django/trunk/django/db/models/fields/__init__.py",
 line 498, in get_prep_value
     return self.to_python(value)
   File "/home/kmt/tmp/django/trunk/django/db/models/fields/__init__.py",
 line 492, in to_python
     raise exceptions.ValidationError(self.error_messages['invalid'])
 ValidationError: [u'This value must be an integer.']

 ----------------------------------------------------------------------
 Ran 82 tests in 13.539s

 FAILED (errors=1)
 }}}

 I kind of thought it was going to and nearly didn't add it, pending some
 resolution between that ticket (#12151) and this one, but on further
 reflection I think the problem is here. If there is existing code that
 handles errors in submitted data by catching !ValueError raised on a get,
 that's going to break if the same error condition now raises
 !ValidationError instead.

 I agree that it's ugly that bad data can cause a plethora of different
 exceptions to be raised -- but switching to one and only one, if that is
 not one that was previously being raised, seems bckwards-incompatible. Am
 I missing something here?

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11716#comment:11>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
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