Opened 10 years ago

Closed 10 years ago

#21619 closed Cleanup/optimization (fixed)

SingleObjectMixin raises ObjectDoesNotExist, rather than a more specific subclass

Reported by: Keryn Knight <django@…> Owned by: pjrharley
Component: Generic views Version: dev
Severity: Normal Keywords:
Cc: pjrharley Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When calling get_object for something which inherits from SingleObjectMixin, the exception caught is ObjectDoesNotExist, when as far as I can tell, based on the Http404 raised, the more specific form of queryset.model.DoesNotExist could be used instead.

I can't see any docs or comments as to a historic (or current) reason it may be catching the generic version (perhaps there are scenarios where the Model's DoesNotExist is not available yet?), and there are probably no implications by casting a wider net than necessary, but I'm opening the ticket anyway in case as a possible cleanup worth doing.

Change History (6)

comment:1 by Marc Tamlyn, 10 years ago

I don't see any reason why we would need the less specific exception.

comment:2 by Marc Tamlyn, 10 years ago

Triage Stage: UnreviewedAccepted

comment:3 by pjrharley, 10 years ago

Cc: pjrharley added
Has patch: set
Owner: changed from nobody to pjrharley
Status: newassigned

comment:4 by Baptiste Mispelon, 10 years ago

Patch needs improvement: set

Hi,

I added some comments on the PR.
Once those are addressed, you can remove the patch needs improvement flag on the ticket.

Thanks.

comment:5 by pjrharley, 10 years ago

Patch needs improvement: unset

Thanks, new commit added to the PR and some comments over there.

comment:6 by Baptiste Mispelon <bmispelon@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In cdd6617da679e19059907979b03c4ef7b15691e6:

Fixed #21619 -- Made SingleObjectMixin.get_object catch a more precise exception.

Thanks to Keryn Knight for the report.

Note: See TracTickets for help on using tickets.
Back to Top