[Django] #34611: Support getting None in qs.get()

22 views
Skip to first unread message

Django

unread,
May 31, 2023, 2:57:11 AM5/31/23
to django-...@googlegroups.com
#34611: Support getting None in qs.get()
-------------------------------------+-------------------------------------
Reporter: Amin | Owner: nobody
Aminian |
Type: New | Status: new
feature |
Component: Database | Version: 4.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `get()` method in `Queryset` class would raise
`self.model.DoesNotExist` exception if no records found for the params.

In cases that we don't want to handle exception and we don't want to use
`try...except`, we use something like this:


{{{
qs.filter(...).first()
}}}

Which would return `None` and then there is no need to handle excpetion.

Can't we have it in `get` method itself ? I mean something like
`get(raise_exception=False)` to return `None` instead of raising
exception.

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

Django

unread,
May 31, 2023, 4:28:53 AM5/31/23
to django-...@googlegroups.com
#34611: Support getting None in qs.get()
-------------------------------------+-------------------------------------
Reporter: Amin Aminian | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | 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: => duplicate


Comment:

Thanks for the report, however it was discussed and rejected multiple
times, e.g. #2659 or #11352.

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

Reply all
Reply to author
Forward
0 new messages