Opened 8 years ago

Closed 8 years ago

#1312 closed enhancement (fixed)

QuerySet.in_bulk demands list, should demand iterable

Reported by: Simon Willison Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The QuerySet.in_bulk method currently uses the following to ensure it has been passed a list of IDs:

def in_bulk(self, id_list):
    assert isinstance(id_list, list), "in_bulk() must be provided with a list of IDs."
    assert id_list != [], "in_bulk() cannot be passed an empty ID list."

This means you can't pass in some other iterable that returns ids, which is a bit of a shame. Suggest doing this instead:

def in_bulk(self, id_list):
    except TypeError:
        assert False, "in_bulk() must be provided with a list of IDs."
    id_list = list(id_list)
    assert id_list != [], "in_bulk() cannot be passed an empty ID list."

Attachments (0)

Change History (1)

comment:1 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2221]) magic-removal: Fixed #1312 -- made QuerySet.in_bulk() accepting of any iterable, not just lists

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.