Code

Ticket #1181: get_in_bulk_empty_list.diff

File get_in_bulk_empty_list.diff, 854 bytes (added by akaihola, 8 years ago)
Line 
1Index: django_src/django/core/meta/__init__.py
2===================================================================
3--- django_src/django/core/meta/__init__.py     (revision 1813)
4+++ django_src/django/core/meta/__init__.py     (working copy)
5@@ -1649,1 +1649,1 @@
6     return select, " FROM " + ",".join(tables) + (where and " WHERE " + " AND ".join(where) or "") + (order_by and " ORDER BY " + order_by or "") + limit_sql, params
7
8 def function_get_in_bulk(opts, klass, *args, **kwargs):
9-    id_list = args and args[0] or kwargs['id_list']
10+    id_list = args and args[0] or kwargs.get('id_list', [])
11     assert id_list != [], "get_in_bulk() cannot be passed an empty list."
12     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)))]
13     kwargs['params'] = id_list