#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.9a0b25d91ced30885310dfe83cf3cc62%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.