Skip to content

Commit

Permalink
Fixed #1181 -- get_in_bulk no longer fails on empty input. Also added…
Browse files Browse the repository at this point in the history
… unit tests. Thanks, akaihola

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1834 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Jan 6, 2006
1 parent 7104000 commit bbfc645
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -31,6 +31,7 @@ And here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS --
people who have submitted patches, reported bugs, added translations, helped
answer newbie questions, and generally made Django that much better:

akaihola
Andreas
David Ascher <http://ascher.ca/>
James Bennett
Expand Down
2 changes: 1 addition & 1 deletion django/core/meta/__init__.py
Expand Up @@ -1649,7 +1649,7 @@ def quote_only_if_word(word):
return select, " FROM " + ",".join(tables) + (where and " WHERE " + " AND ".join(where) or "") + (order_by and " ORDER BY " + order_by or "") + limit_sql, params

def function_get_in_bulk(opts, klass, *args, **kwargs):
id_list = args and args[0] or kwargs['id_list']
id_list = args and args[0] or kwargs.get('id_list', [])
assert id_list != [], "get_in_bulk() cannot be passed an empty list."
kwargs['where'] = ["%s.%s IN (%s)" % (db.db.quote_name(opts.db_table), db.db.quote_name(opts.pk.column), ",".join(['%s'] * len(id_list)))]
kwargs['params'] = id_list
Expand Down
4 changes: 4 additions & 0 deletions tests/testapp/models/lookup.py
Expand Up @@ -65,6 +65,10 @@ def __repr__(self):
{3: Article 3}
>>> articles.get_in_bulk([1000])
{}
>>> articles.get_in_bulk([])
Traceback (most recent call last):
...
AssertionError: get_in_bulk() cannot be passed an empty list.
# get_values() is just like get_list(), except it returns a list of
# dictionaries instead of object instances -- and you can specify which fields
Expand Down

0 comments on commit bbfc645

Please sign in to comment.