Ticket #1565: in_bulk-empty-list.diff

File in_bulk-empty-list.diff, 776 bytes (added by Antti Kaihola, 19 years ago)

patched in_bulk() returns {} if id_list is [] or ()

  • django/db/models/query.py

     
    213213                "Cannot use 'limit' or 'offset' with in_bulk"
    214214        assert isinstance(id_list, (tuple,  list)), "in_bulk() must be provided with a list of IDs."
    215215        id_list = list(id_list)
    216         assert id_list != [], "in_bulk() cannot be passed an empty ID list."
     216        if id_list == []:
     217            return {}
    217218        qs = self._clone()
    218219        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))))
    219220        qs._params.extend(id_list)
Back to Top