From bbfc645337610b4c974c4f5a225958367b4d294c Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 6 Jan 2006 20:43:14 +0000 Subject: [PATCH] Fixed #1181 -- get_in_bulk no longer fails on empty input. Also added unit tests. Thanks, akaihola git-svn-id: http://code.djangoproject.com/svn/django/trunk@1834 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/core/meta/__init__.py | 2 +- tests/testapp/models/lookup.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 42f73a2d12..73fe3078c9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -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 James Bennett diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 2b187d542e..dd048d4637 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -1649,7 +1649,7 @@ def function_get_sql_clause(opts, **kwargs): 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 diff --git a/tests/testapp/models/lookup.py b/tests/testapp/models/lookup.py index f8445c4f60..2362bcbef9 100644 --- a/tests/testapp/models/lookup.py +++ b/tests/testapp/models/lookup.py @@ -65,6 +65,10 @@ Article 4 {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