# why do DoesNotExist exceptions lack any useful information?

**URL:** <https://forum.djangoproject.com/t/why-do-doesnotexist-exceptions-lack-any-useful-information/46258>\
**Category:** Using the ORM\
**Created:** [October 23, 2026, 5:25pm UTC](https://forum.djangoproject.com/t/why-do-doesnotexist-exceptions-lack-any-useful-information/46258 "2026-10-23T17:25:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonLeary42](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/simonleary42/32/28121_2.png) [@simonLeary42](https://forum.djangoproject.com/u/simonLeary42)\
**Post date:** [October 23, 2026, 5:25pm UTC](https://forum.djangoproject.com/t/why-do-doesnotexist-exceptions-lack-any-useful-information/46258/1 "2026-10-23T17:25:04Z")

</div>

I am accustomed to `KeyError` giving me useful information. If you get `KeyError("foobar")`, you know that `"foobar"` was not found. But in Django, when you do `User.objects.get(username="simon")` for example, you get back `User.DoesNotExist("User matching query does not exist.")`. There is no information in the exception’s `args` that I can’t already infer based on the type of the exception. Why must it be this way?

I made myself a wrapper function:

```python
def get_object(model, **kwargs):
    try:
        return model.objects.get(**kwargs)
    except model.DoesNotExist as e:
        e.args = [str(kwargs)]
        raise

```

With this wrapper function you get back `User.DoesNotExist("{'username': 'simon'}")`. Is there a reason this should not be the default Django experience?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 23, 2026, 7:25pm UTC](https://forum.djangoproject.com/t/why-do-doesnotexist-exceptions-lack-any-useful-information/46258/2 "2026-10-23T19:25:00Z")

</div>

`<conjecture>`  
My guess would be that it’s probably related to the issue that the `.get` method is applied to a queryset, and doesn’t necessarily have all the information to accurately report the conditions of the error.

As a trivial example, consider the following:  
`user.objects.filter(is_staff=True).exclude(is_supervisor=True).get(username='ken')`

Reporting `User.DoesNotExist("{'username': 'ken'}")` isn’t really accurate, is it?

I’m guessing that all the information is there somewhere in the QuerySet object, but I’d also guess that the effort involved in digging it out to the point of producing a valid and useful error message probably exceeds the benefit obtained from doing so.  
`</conjecture>`

---

<div class="post-metadata">

**Author:** ![simonLeary42](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/simonleary42/32/28121_2.png) [@simonLeary42](https://forum.djangoproject.com/u/simonLeary42)\
**Post date:** [October 23, 2026, 7:51pm UTC](https://forum.djangoproject.com/t/why-do-doesnotexist-exceptions-lack-any-useful-information/46258/3 "2026-10-23T19:51:48Z")

</div>

Oh, that makes sense, thanks.
