1. Luke Plant
  2. django

Commits

adr...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed d3da414

Fixed #1181 -- get_in_bulk no longer fails on empty input. Also added unit tests. Thanks, akaihola

  • Participants
  • Parent commits 1d5102b
  • Branches default

Comments (0)

Files changed (3)

File AUTHORS

View file
  • Ignore whitespace
 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

File django/core/meta/__init__.py

View file
  • Ignore whitespace
     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

File tests/testapp/models/lookup.py

View file
  • Ignore whitespace
 {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