[Django] #28681: QuerySet.get() implies LIMIT 2

2 views
Skip to first unread message

Django

unread,
Oct 4, 2017, 12:56:11 PM10/4/17
to django-...@googlegroups.com
#28681: QuerySet.get() implies LIMIT 2
-------------------------------------+-------------------------------------
Reporter: Дилян | Owner: nobody
Палаузов |
Type: | Status: new
Uncategorized |
Component: Database | Version: 1.11
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 |
-------------------------------------+-------------------------------------
If the database finds at least two results upon QuerySet.get() it can stop
working, and Django will raise anyway MultipleObjectsReturned .

{{{
diff --git a/django/db/models/query.py b/django/db/models/query.py
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -370,9 +370,10 @@ class QuerySet(object):
clone = self.filter(*args, **kwargs)
if self.query.can_filter() and not self.query.distinct_fields:
clone = clone.order_by()
+ clone = clone[:2]
num = len(clone)
if num == 1:
- return clone._result_cache[0]
+ return clone[0]
if not num:
raise self.model.DoesNotExist(
"%s matching query does not exist." %
}}}

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

Django

unread,
Oct 4, 2017, 1:39:51 PM10/4/17
to django-...@googlegroups.com
#28681: QuerySet.get() implies LIMIT 2
-------------------------------------+-------------------------------------
Reporter: Дилян Палаузов | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
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 Tim Graham):

* type: Uncategorized => Cleanup/optimization


Comment:

Duplicate of #6785.

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

Django

unread,
Oct 4, 2017, 2:04:57 PM10/4/17
to django-...@googlegroups.com
#28681: QuerySet.get() implies LIMIT 2
-------------------------------------+-------------------------------------
Reporter: Дилян Палаузов | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: 1.11
(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 Дилян Палаузов):

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


--
Ticket URL: <https://code.djangoproject.com/ticket/28681#comment:2>

Reply all
Reply to author
Forward
0 new messages