1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

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
This commit is contained in:
Adrian Holovaty 2006-04-11 03:15:22 +00:00
parent 59f47eaf1f
commit 308548f0dd
2 changed files with 3 additions and 4 deletions

View File

@ -213,7 +213,8 @@ class QuerySet(object):
"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 File

@ -67,9 +67,7 @@ Article 4
>>> 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):
...