django/django — pull request #3277 by artemrizhov (2014-09-25 23:25:05+00:00)
Title: Second solution for IndexError problem in QuerySet

This is a fix for problem described in ticket #23555 https://code.djangoproject.com/ticket/23555

I've sent a pull request with a fix already https://github.com/django/django/pull/3274
But if somebody thinks the code becomes too complicated and prefers to use try/catch despite the problem then I propose this solution with special exception class. Now you can use this safely anywhere:
```
try:
return qs[0]
except QuerySetIndexError:
return None
```