Hi,

I have the following code in my views.py
...
try:
    q = models.Queue.objects.filter(type=type, status=0)[0]
except models.Queue.DoesNotExist:
    return WebAPIResponseError(request, DOES_NOT_EXIST)
...

this would give back the first result that corresponds to type=type
and has status 0.

In my tests.py I've tried to call a non-existing type, and this gives
me an IndexError with the following traceback:

======================================================================
ERROR: Testing requesting nonexisting type
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/nagyv/workspace/Cosci/adminka/../adminka/queuemanager/tests.py",
line 76, in test_get_next_wrongkey
    rsp = self.get_next('noSuchKey')
  File "/home/nagyv/workspace/Cosci/adminka/../adminka/queuemanager/tests.py",
line 47, in get_next
    rsp = self.api_get('take/%s' % type)
  File "/home/nagyv/workspace/Cosci/adminka/../adminka/queuemanager/tests.py",
line 13, in api_get
    response = self.client.get('/queue/%s/' %path, data)
  File "/usr/lib/python2.5/site-packages/django/test/client.py", line
218, in get
    return self.request(**r)
  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py",
line 82, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/nagyv/workspace/Cosci/adminka/queuemanager/views.py",
line 51, in get_next
    q = models.Queue.objects.filter(type=type, status=0)[0]
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py",
line 129, in __getitem__
    return list(qs)[0]
IndexError: list index out of range

I've tried to catch IndexError as well, but it fails with the same error
try:
        q = models.Queue.objects.filter(type=type, status=0)[0]
    except models.Queue.DoesNotExist, IndexError:
        return WebAPIResponseError(request, DOES_NOT_EXIST)

Any ideas how to catch the error?

Viktor

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to