#34683 closed Cleanup/optimization (wontfix)

get_object_or_404 and get_list_or_404 custom messaging

Reported by: Emanuel Owned by: nobody
Component: HTTP handling Version: 4.2
Severity: Normal Keywords: HTTP 404
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Is there a possibility to add a message parameter to get_object_or_404 and get_list_or_404? This function is lovely and reduces boilerplate a lot. In the view that I'm currently using it, I have business logic that depends on finding other models first, and having a message should be excellent since the lack of a message parameter sends me back to using try-catch or if-None statements.

I know there might be another design or security feature as well but the gain in my code would be significant.

Change History (1)

comment:1 by Mariusz Felisiak, 17 months ago

Resolution: wontfix
Status: newclosed

Thanks for this ticket, however we don't want to complicate this shortcuts. You can always add a small wrapper in your app, e.g.

def my_get_object_or_404(klass, message, *args, **kwargs):
    try:
        return get_object_or_404(klass, *args, **kwargs)
    except Http404:
        if message:
            raise Http404(message)
        else:
            raise
Note: See TracTickets for help on using tickets.
Back to Top