Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

magic-removal: Fixed #1565 -- in_bulk() now returns empty dictionary …

…if passed an empty list of IDs

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2663 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 308548f0dde38025b0aa6f9b4b3dc90b41ddbd42 1 parent 59f47ea
@adrianholovaty adrianholovaty authored
Showing with 3 additions and 4 deletions.
  1. +2 −1  django/db/models/query.py
  2. +1 −3 tests/modeltests/lookup/models.py
View
3  django/db/models/query.py
@@ -213,7 +213,8 @@ def in_bulk(self, id_list):
"Cannot use 'limit' or 'offset' with in_bulk"
assert isinstance(id_list, (tuple, list)), "in_bulk() must be provided with a list of IDs."
id_list = list(id_list)
- assert id_list != [], "in_bulk() cannot be passed an empty ID list."
+ if id_list == []:
+ return {}
qs = self._clone()
qs._where.append("%s.%s IN (%s)" % (backend.quote_name(self.model._meta.db_table), backend.quote_name(self.model._meta.pk.column), ",".join(['%s'] * len(id_list))))
qs._params.extend(id_list)
View
4 tests/modeltests/lookup/models.py
@@ -67,9 +67,7 @@ def __repr__(self):
>>> Article.objects.in_bulk([1000])
{}
>>> Article.objects.in_bulk([])
-Traceback (most recent call last):
- ...
-AssertionError: in_bulk() cannot be passed an empty ID list.
+{}
>>> Article.objects.in_bulk('foo')
Traceback (most recent call last):
...
Please sign in to comment.
Something went wrong with that request. Please try again.