[Django] #34683: get_object_or_404 and get_list_or_404 custom messaging

6 views
Skip to first unread message

Django

unread,
Jun 28, 2023, 10:50:58 PM6/28/23
to django-...@googlegroups.com
#34683: get_object_or_404 and get_list_or_404 custom messaging
------------------------------------------------+--------------------------
Reporter: eavendano | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 4.2
Severity: Normal | Keywords: HTTP 404
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+--------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34683>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 29, 2023, 12:11:38 AM6/29/23
to django-...@googlegroups.com
#34683: get_object_or_404 and get_list_or_404 custom messaging
-------------------------------------+-------------------------------------
Reporter: eavendano | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: HTTP handling | Version: 4.2
Severity: Normal | Resolution: wontfix

Keywords: HTTP 404 | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

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.
{{{#!python
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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34683#comment:1>

Reply all
Reply to author
Forward
0 new messages