model.DoesNotExist exception raised by QuerySet.get() should include the same nice description of parameters that the MultipleObjectsReturned exception does.
|Reported by:||aaron||Owned by:||trentm|
|Component:||Database layer (models, ORM)||Version:|
|Severity:||Normal||Keywords:||model.DoesNotExist, ObjectDoesNotExist, QuerySet.get error message kwargs parameters|
|Cc:||asokoloski@…, boxed||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||yes|
The current message contained in a DoesNotExist (ObjectDoesNotExist) exception raised by QuerySet.get(...) is roughly:
"%s matching query does not exist." % MODEL_NAME
But the MultipleObjectsReturned exception raised by the same function looks like:
"get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (MODEL_NAME, NUMBER_OF_OBJECTS, KWARGS)
with KWARGS being the keyword arguments passed to the get(...) method. This is great for investigating error message emails sent from a live site -- it makes it really easy to find out which object you were trying to get, and how to fix the root cause.
Change History (19)
Changed 7 years ago by