Author: kmtracey Date: 2008-10-22 18:14:48 -0500 (Wed, 22 Oct 2008) New Revision: 9246
Modified: django/branches/releases/1.0.X/ django/branches/releases/1.0.X/django/contrib/admin/views/main.py django/branches/releases/1.0.X/tests/regressiontests/admin_views/tests.py Log: [1.0.X] Fixed #9252 -- Moved the try/except protecting against incorrect lookup params to where the error is now raised, and added a test for this case. Backport of [9245] from trunk. Property changes on: django/branches/releases/1.0.X ___________________________________________________________________ Name: svnmerge-integrated - /django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9241 + /django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9245 Modified: django/branches/releases/1.0.X/django/contrib/admin/views/main.py =================================================================== --- django/branches/releases/1.0.X/django/contrib/admin/views/main.py 2008-10-22 23:09:35 UTC (rev 9245) +++ django/branches/releases/1.0.X/django/contrib/admin/views/main.py 2008-10-22 23:14:48 UTC (rev 9246) @@ -99,14 +99,7 @@ def get_results(self, request): paginator = Paginator(self.query_set, self.list_per_page) # Get the number of objects, with admin filters applied. - try: - result_count = paginator.count - # Naked except! Because we don't have any other way of validating - # "params". They might be invalid if the keyword arguments are - # incorrect, or if the values are not in the correct type (which would - # result in a database error). - except: - raise IncorrectLookupParameters + result_count = paginator.count # Get the total number of objects, with no admin filters applied. # Perform a slight optimization: Check to see whether any filters were @@ -192,7 +185,15 @@ lookup_params[key] = value.split(',') # Apply lookup parameters from the query string. - qs = qs.filter(**lookup_params) + try: + qs = qs.filter(**lookup_params) + # Naked except! Because we don't have any other way of validating "params". + # They might be invalid if the keyword arguments are incorrect, or if the + # values are not in the correct type, so we might get FieldError, ValueError, + # ValicationError, or ? from a custom field that raises yet something else + # when handed impossible data. + except: + raise IncorrectLookupParameters # Use select_related() if one of the list_display options is a field # with a relationship. Modified: django/branches/releases/1.0.X/tests/regressiontests/admin_views/tests.py =================================================================== --- django/branches/releases/1.0.X/tests/regressiontests/admin_views/tests.py 2008-10-22 23:09:35 UTC (rev 9245) +++ django/branches/releases/1.0.X/tests/regressiontests/admin_views/tests.py 2008-10-22 23:14:48 UTC (rev 9246) @@ -160,7 +160,14 @@ '<a href="?color__id__exact=3">Blue</a>' in response.content, "Changelist filter not correctly limited by limit_choices_to." ) - + + def testIncorrectLookupParameters(self): + """Ensure incorrect lookup parameters are handled gracefully.""" + response = self.client.get('/test_admin/admin/admin_views/thing/', {'notarealfield': '5'}) + self.assertRedirects(response, '/test_admin/admin/admin_views/thing/?e=1') + response = self.client.get('/test_admin/admin/admin_views/thing/', {'color__id__exact': 'StringNotInteger!'}) + self.assertRedirects(response, '/test_admin/admin/admin_views/thing/?e=1') + def get_perm(Model, perm): """Return the permission object, for the Model""" ct = ContentType.objects.get_for_model(Model) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---